如何使用C#获取文档内容创建日期 [英] How to get Document Content Created Date using c#

查看:79
本文介绍了如何使用C#获取文档内容创建日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建MS Word加载项,并且想知道如何获取活动文档的内容创建日期.可以通过转到文档的属性",然后在详细信息"选项卡中找到此字段.

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.

到目前为止,请参阅下面的代码.但是,这将返回错误的日期值"1/01/1601 11:00:00 AM".实际的内容创建日期为"05/09/2015 11:53 AM"

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();

推荐答案

无需使用该文件.只需使用内置的文档属性即可:

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;
    }

这篇关于如何使用C#获取文档内容创建日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆