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)
Click the Insert tab and choose Field from the Quick Parts dropdown in the Text group (Figure A). In Word 2003, you'll find this setting in the AutoText options. Select FileName from the Field Names list. If you want to display the full path, check the Add Path To FileName Option (Figure B).
Go to Insert > Header or Footer. Select Edit Header or Edit Footer. Select Quick Parts, and select Field. In the Field names list, choose the field you want (such as FileName, Date, Author, or Title), choose the format you want in the Field properties section.
Select File -> Print and go to the Caption panel in the Print dialog window. Select Filename or None from the Type drop-down menu. If the Filename has been selected, press the Font button to alter the size and font.
Files that suddenly appear with a tilde are usually backups of a file that was opened or still opened. For example, with a file called myfile. doc, when it is opened in Microsoft Word, the ~$myfile. doc is created. It is a temporary backup file, used to recover data if the software crashes or stops unexpectedly.
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
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