1

I'm creating a MS Word addin and would like to know how I can get the Content Created Date of the Active Document. This field can be found by going to the Properties of the Document, and then in the Details tab.

See my code below so far. However, this is returning the an incorrect date value of "1/01/1601 11:00:00 AM". The actual Content Created Date is "05/09/2015 11:53AM"

            string docName = Globals.ThisAddIn.Application.ActiveDocument.Name;

            string res = Path.GetFileNameWithoutExtension(docName);

            string fileloc = Path.GetFullPath(docName);

            FileInfo fi = new FileInfo(fileloc);
            Word.Application objApplication = Globals.ThisAddIn.Application;
            Word.Selection objSelection = objApplication.Selection;
            Word.Range objRange = objSelection.Range;
            objRange.InsertAfter(fi.CreationTime.ToString());
            objRange.Collapse(Word.WdCollapseDirection.wdCollapseEnd);
            objRange.Select();
razor_ray
  • 55
  • 1
  • 11
  • http://stackoverflow.com/questions/17581245/getting-content-created-date-of-an-excel-file I think that it is applicable to Word too – Matteo Umili Sep 25 '15 at 07:21

1 Answers1

0

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;
    }
Charlie
  • 376
  • 1
  • 7