I'm using WinForms. I have a form that has a button.
Goal: On button click: Open up a word document. Where the file path is hard coded into the program. I don't want the users to have to locate the word document.
Problem: I receive this error message. When I wrote my code, I get a red error line under 'Application'.
private void button1_Click(object sender, EventArgs e)
{
this.Application.Documents.Open(@"C:\Test\NewDocument.docx", ReadOnly:true)
}
Under “Computer” on the right side of the backstage screen, either select the “Current Folder,” a folder under “Recent Folders,” or click the “Browse” button at the bottom of the list. The path to the location of the currently open file displays in the address bar at the top of the “Save As” dialog box.
Instead of adding interop in your reference, you may also consider to use this:
System.Diagnostics.Process.Start(@"C:\Test\NewDocument.docx");
first add the dll of Microsoft.Office.Interop.Word
to your references then add this:
using Microsoft.Office.Interop.Word;
and use the following code:
Application ap = new Application();
Document document = ap.Documents.Open(@"C:\Test\NewDocument.docx");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With