How do I get this property in c#?
How do I get the value of the property as an example?
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;
}
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.