簡體   English   中英

如何獲得原產地的“內容創建”? C#Winform

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

如何在c#中獲取此屬性?

屬性截圖

我如何獲得該屬性的值作為示例?

參考如何使用c#獲取文檔內容創建日期

無需使用該文件。 只需使用內置文檔屬性:

 internal DateTime GetContentCreatedDate()
 {
        Word.Document doc = Globals.ThisAddIn.Application.ActiveDocument;
        Office.DocumentProperties properties = (Office.DocumentProperties)doc.BuiltInDocumentProperties;
        return (DateTime)properties[Word.WdBuiltInProperty.wdPropertyTimeCreated].Value;
 }

我已經能夠獲得新的Office文件格式的數據(例如:.docx,.xlsx等)。

新的office文件格式本質上是Zip文件,里面有XML數據。

“創建內容”日期保存在標簽“ dcterms:created ”中的XML文件“ docProps\\core.xml ”中。

一個例子可能是:

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

我仍然在研究舊的文件格式,但OpenMCDF是那些前進的方式。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM