本文介绍了写入文件扩展属性“修订号"在所有类型的文件上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用c#读/写窗口信息文件(扩展文件属性)

I would like to read/write the window information file (extended file properties) using c#

通过执行以下操作找到的:在窗口资源管理器中右键单击 => 属性 => 摘要选项卡.我主要想访问这些属性:

The one found by doing the following: In window explorer right click => properties => Summary tab. I want mainly to have access to the properties:

  • 标题
  • 类别
  • 修订号

对于办公文档,我可以使用以下(使用 Office.Interop)或使用 DSOFile

For office document I can use the following (using Office.Interop) or using DSOFile

    private static string GetExcelWorkbookPropertyValue(_Workbook workbook, string propertyName)
    {
        DocumentProperties builtInProperties = (DocumentProperties)workbook.BuiltinDocumentProperties;
        string value = builtInProperties.Cast<DocumentProperty>().First(x => x.Name.Equals(propertyName, StringComparison.InvariantCultureIgnoreCase)).Value;
        return value ?? "";
    }

但我想要的是一个适用于所有文件的更通用的解决方案.

But what i would like is a more general solution that will work with all files.

有人可以帮忙吗?

问题附加信息您还可以使用Shell32读取属性Title和Category

Question additional information you can also read the properties Title and Category by using Shell32

        Shell32.Shell shell = new Shell32.Shell();
        //set the namespace to file path
        Shell32.Folder folder = shell.NameSpace(Path.GetDirectoryName(file));
        //get ahandle to the file
        Shell32.FolderItem folderItem = folder.ParseName(Path.GetFileName(file));
        //did we get a handle ?
        if (folderItem != null)
        {
            for (int i = 0; i < 100; i++)
            {
                string s = folder.GetDetailsOf(folderItem, i);
                System.Diagnostics.Debug.WriteLine(s);
            }
        }

不过我还是写了revision number这个属性,不过貌似revision number是office文档属性,不能写(估计会打断office的跟踪流程).

However I still write the properity Revision Number, however it's look like Revision number is an office document property and cannot be written (I guess it will break the tracking process of office).

没有意义的是我可以使用窗口资源管理器修改它,并且该属性对于非办公文档也是可见的......我正在努力理解这一点.

What does not make sense is that I can modify it using window explorer and the property is also visible for non-office documents... I'm struggling to understand that.

推荐答案

此信息存储在 属性.以下是一些标准属性.不过,我不确定 .NET Framework 是否提供了这些接口的包装器.

This information is stored in properties. Here are some of the standard properties. I'm not sure if the .NET Framework provides a wrapper around these interfaces, though.

这篇关于写入文件扩展属性“修订号"在所有类型的文件上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 01:50
查看更多