March 21st, 2013, 10:42 AM
How to open to develop a C Sharp Word Add In that acts the same as File>Open
I am developing a C Sharp Word AddIn that acts the same as the File>Open option. The exception is that when I click on the AddIn, I want it to ask the user which file they want to open...
I have .NET Framework 4, Visual Studio 2010 and Word 2010.
Here is the code so far...
using Word = Microsoft.Office.Interop.Word;
using Office = Microsoft.Office.Core;
public partial class ThisAddIn
private void ThisAddIn_Startup(object sender, System.EventArgs e)
System.Console.Write("Enter the file name: ");
String fileName = System.Console.ReadLine();
Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application();
oDoc = oWord.Documents.Open(@"H:\SNH\" + fileName);
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
#region VSTO generated code
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
private void InternalStartup()
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
When I add the AddIn to Word and try to run it, it produces an error saying "This file could not be found." However, it was supposed to ask the user which file to open and never did.
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.