How can I get the filename of a Word document from C#?

I’m working on a MS Word AddIn (VSTO).
The idea is that I work on a Word document and I send it somewhere.

I have all the code I need except one thing: is there a way I can get the filename of the Word document I’m working on? (assuming that is already saved)

this.FullName property in the code-behind .cs file should give you the entire path of the current doc.

Here’s the exact query in my QuickWatch window.

((Microsoft.Office.Tools.Word.Document)(this)).FullName

the above did not work for me however this did

Document vstoDocument = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
string name = vstoDocument.Name
MessageBox.Show(name);

Leave a Comment