Search code examples
c#ms-wordopenxml

WordprocessingDocument object: get filename property


Is it possible to get the filename property of a WordProcessingDocument object? I know when you instantiate the object, you need to provide a path to the file, but I need to get that filename from the instantiated object.

Stream stream = new FileStream(@"C:\Users\username\Documents\DOCUMENT_NAME.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

WordprocessingDocument doc = WordprocessingDocument.Open(stream, false);

I want to get the 'DOCUMENT_NAME' String from the doc object.


Solution

  • I personally prefer to use the office COM assemblies for communication between my application and any office document. it gives you more functionalities and it's quite easy to use.

    Include the namespace Microsoft.Office.Interoperability.Word in your code to start with that.

    Declare a Word.Application Object and use it to open, edit, extract data from your word document, including documents properties.

    Leave filestream for handling large text files.