简体   繁体   English

如何获得原产地的“内容创建”? C#Winform

[英]How to get “Content Created” of origin property? C# Winform

How do I get this property in c#? 如何在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# 参考如何使用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 (eg: .docx, .xlsx etc.). 我已经能够获得新的Office文件格式的数据(例如:.docx,.xlsx等)。

New office file formats are essentially Zip files, with XML data inside. 新的office文件格式本质上是Zip文件,里面有XML数据。

The "Content Created" date is held in the XML file " docProps\\core.xml " within the tag " dcterms:created ". “创建内容”日期保存在标签“ dcterms:created ”中的XML文件“ docProps\\core.xml ”中。

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. 我仍然在研究旧的文件格式,但OpenMCDF是那些前进的方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM