How to: Retrieve application property values from a word processing document (Open XML SDK)
This topic shows how to use the classes in the Open XML SDK 2.5 for Office to programmatically retrieve an application property from a Microsoft Word 2013 document, without loading the document into Word. It contains example code to illustrate this task.
Last modified: March 22, 2013
Applies to: Office 2013 | Open XML
To use the sample code in this topic, you must install the Open XML SDK 2.5. You must explicitly reference the following assemblies in your project:
-
WindowsBase
-
DocumentFormat.OpenXml (installed by the Open XML SDK)
You must also use the following using directives or Imports statements to compile the code in this topic.
To retrieve application document properties, you can retrieve the ExtendedFilePropertiesPart property of a WordprocessingDocument object, and then retrieve the specific application property you need. To do this, you must first get a reference to the document, as shown in the following code.
Given the reference to the WordProcessingDocument object, you can retrieve a reference to the ExtendedFilePropertiesPart property of the document. This object provides its own properties, each of which exposes one of the application document properties.
Once you have the reference to the properties of ExtendedFilePropertiesPart, you can then retrieve any of the application properties, using simple code such as that shown in the next example. Note that the code must confirm that the reference to each property isn't null before retrieving its Text property. Unlike core properties, document properties aren't available if you (or the application) haven't specifically given them a value.
|
Contribute to this article Want to edit or suggest changes to this content? You can edit and submit changes to this article using GitHub. |