向文件添加新的元数据属性 [英] Add new metadata properties to a file

查看:95
本文介绍了向文件添加新的元数据属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想向某些文件添加一些元数据属性.就像文档文件的所有者,计算机,标题,主题等一样,我希望能够添加一些自定义属性.该怎么办?

I want to add some metadata properties to some files. Just like there are Owner, Computer, Title, Subject, etc for doc files, I want to be able to add some custom attributes. How can that be done?

推荐答案

如上所述,它取决于文件系统. 因此,这仅适用于NTFS.

As already mentioned it depends on the filesystem. So this will only work with NTFS.

一种创建ADS流的方法:请参阅编辑历史记录.

One way is creating ADS streams: See the edit history.

另一种方法是使用DSOFile-Library,该库仅适用于Office文件. 但是它适用于每个文件.

Another way is using the DSOFile-Library, which is intended to work on Office files only. But it works on every file.

首先在此处下载该库(x64 + x86):下载

First of all download the library here (x64+x86): DOWNLOAD

重要提示: 由于DSO OLE是32位DLL,因此只有在将编译目标CPU设置为x86时,它才起作用.否则会抛出异常. 还有64位版本可用:如何在c#

IMPORTANT: Since DSO OLE is 32bit DLL it will only work, when you set your compilation target CPU to x86. Otherwise it will throw an Exception. There's also a 64bit version avaliable: How to read custom file properties in c#

然后在您的项目中创建对COM DLL的引用(右键单击解决方案->添加引用-> COM选项卡->添加"DSO OLE文档属性阅读器v2.1")并使用名称空间:

Then create a refernce to the COM DLL in your project (Right click on the solution -> Add reference -> COM tab -> Add "DSO OLE Document Property Reader v2.1") and use the namespace:

using DSOFile;

之后,您可以创建自己的属性:

After that you can create your own attributes:

首先打开文件:

OleDocumentProperties myFile = new DSOFile.OleDocumentProperties();
myFile.Open(@"MYPATHHERE", false, DSOFile.dsoFileOpenOptions.dsoOptionDefault);

为yourValue创建一个对象:object yourValue = "Your Value";

Create a object for yourValue: object yourValue = "Your Value";

然后检查是否已经有想要创建的属性:

Then check if there's already a property like the one you want to create:

foreach (DSOFile.CustomProperty property in myFile.CustomProperties)
{
   if (property.Name == "Your Property Name"){
      //Property exists
      //End the task here (return;) oder edit the property
      property.set_Value(yourValue);
   }
}

然后在检查现有属性后,可以添加属性:

Then after checking for existing attributes, you can add the attribute:

myFile.CustomProperties.Add("Your Property Name", ref yourValue);

要完成任务,请保存并关闭文件:

To finish the task, save and close the file:

myFile.Save();
myFile.Close(true);

您可以在我的主页上下载示例项目.

You can download a sample project on my homepage.

现在到在浏览器中显示属性的部分.

Now to the part of showing the attributes in the explorer.

您必须为此创建一个shell扩展.有关更多信息,请访问代码项目"页面.

You have to create a shell extension for that. For more info on that, visit the Codeproject page.

我创建了一个,您可以在此处下载.您必须再次签名(在提到的页面上查找操作方法").

I created one, you can download it here. But you have to sign it again (look for a "how-to" on the mentioned page).

右键单击.css/.js/.txt文件时,它看起来像这样:
或创建自己的属性标签:

您可以在此处下载示例:下载

It will look like that, when right-clicking on a .css/.js/.txt-file:
Or create your own properties tab:

You can download the sample here: DOWNLOAD

有关Dsofile.dll和其他来源的更多信息,请参见

For more information about Dsofile.dll and other source see Microsoft Dsofile.dll

这篇关于向文件添加新的元数据属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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