2

How do I get this property in c#?

property screenshot

How do I get the value of the property as an example?

almcd
  • 1,069
  • 2
  • 16
  • 29
ahmsyaf
  • 23
  • 4

2 Answers2

0

with the reference from How to get Document Content Created Date using c#

No need to use the file. Just use the built-in document properties:

 internal DateTime GetContentCreatedDate()
 {
        Word.Document doc = Globals.ThisAddIn.Application.ActiveDocument;
        Office.DocumentProperties properties = (Office.DocumentProperties)doc.BuiltInDocumentProperties;
        return (DateTime)properties[Word.WdBuiltInProperty.wdPropertyTimeCreated].Value;
 }
Community
  • 1
  • 1
Rahul Hendawe
  • 902
  • 1
  • 14
  • 39
0

I have been able to get this data for NEW Office File Formats (e.g.: .docx, .xlsx etc.).

New office file formats are essentially Zip files, with XML data inside.

The "Content Created" date is held in the XML file "docProps\core.xml" within the tag "dcterms:created".

An example might be:

using System.IO.Compression;
using System.Xml;

ZipArchive archive = new ZipArchive(file.OpenBinaryStream());
var stream = archive.GetEntry(@"docProps/core.xml").Open();
using (var reader = XmlReader.Create(stream))
{
    for (reader.MoveToContent(); reader.Read();)
        if (reader.NodeType == XmlNodeType.Element && reader.Name == "dcterms:created")
        {
            stream.Close();
            return DateTime.Parse(reader.ReadElementString());
        }
}

I'm still looking into the old file formats, but OpenMCDF is the way forward for those.

OutOfThisPlanet
  • 336
  • 3
  • 17