2

I want to use C# to get the metadata of a file, for example a docx. In the screenshot below you see the auteur and other metadata of a file.

Example

How do I write this metadata to the console?

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Mister Verleg
  • 4,053
  • 5
  • 43
  • 68
  • 1
    duplicate of http://stackoverflow.com/questions/9684368/how-to-read-metadata-information-from-docx-documents –  May 09 '16 at 13:05
  • Possible duplicate of [Read/Write 'Extended' file properties (C#)](http://stackoverflow.com/questions/220097/read-write-extended-file-properties-c) – Vedran May 09 '16 at 13:07
  • @PranavPatel It i similar but not the same, the question you show asks how eddit this data non-programmatic, i want to write this data to the console – Mister Verleg May 09 '16 at 13:09
  • @Peterverleg read the answer carefully in http://stackoverflow.com/questions/9684368/how-to-read-metadata-information-from-docx-documents , it also provided full project demo –  May 09 '16 at 13:09
  • 1
    here is the demo solution https://onedrive.live.com/?authkey=%21AF_z1mFM432Nt8c&cid=6514BC76687E775B&id=6514BC76687E775B%21131&parId=6514BC76687E775B%21124&action=locate –  May 09 '16 at 13:10
  • 1
    If you can use Word automation, just pick them out of [Document.BuiltInDocumentProperties](https://msdn.microsoft.com/en-us/library/office/ff196862.aspx) – stuartd May 09 '16 at 13:10
  • Thank you I will check if it is a duplicate and if it is i will close my question. – Mister Verleg May 09 '16 at 13:11

1 Answers1

3

A word file in DOCX is packaged as a zip file. The metadata is in an XML file within that zip file. As a very simple way to think about it, this is what you would need to do programmatically through C#:

  1. Unzip the DOCX file into it's folder structure.
  2. Open the core.xml file located in the docProps folder of that structure.
  3. Pull out and store the relevant XML elements that you are looking for, such as title, subject or whatever.
  4. Write those elements with Console.WriteLine().

Image Showing Structure and XML file

Info on Office Open XML format

Mark G
  • 557
  • 1
  • 6
  • 17