问题描述
我想在文件系统中添加和检索文件的标签.
I would like to add and retrieve tags of files in File System.
由于您可以将 Stackoverflow 问题标记到相关主题,因此您可以在 Windows 文件系统中标记文件:
As you can tag Stackoverflow question to the relevant topics, you can tag a file in Windows file-system:
以下方式不能让我访问文件的标签,而只能访问其他文件属性.
The following way doesn't give me access to the tags of the file, but only to other file properties.
string file = @"C:UsersmeDesktopMyFile.doc";
FileInfo oFileInfo = new FileInfo(file);
MessageBox.Show(oFileInfo.FullName);
任何想法如何使用 System.IO
的简单 API 访问标签?
Any ideas how to access the tags using the simple API of System.IO
?
推荐答案
由于您可以将 Stackoverflow 问题标记到相关主题,因此您可以在 Windows 文件系统中标记文件
As you can tag Stackoverflow question to the relevant topics, you can tag a file in Windows file-system
这个假设是错误的.您不能将标签添加到所有文件类型.请参阅这里一个>:
This assumption is wrong. You can't add tags to all file types. See here:
注意
您无法添加或修改某些类型文件的文件属性.例如,您可以添加或修改 Microsoft 的属性Office 文档和搜索,但您不能添加或修改TXT 或 RTF 文件的属性.
You cannot add or modify the file properties of some types of files. For example, you can add or modify the properties of Microsoft Office documents and Searches, but you can't add or modify the properties of TXT or RTF files.
除了提到的类型之外,还有其他可以包含自定义标签的类型:
Besides the types mentioned there are others which can contain custom tags:
- mp3文件可以包含各种版本的ID3标签
- flac 和 ogg 文件可以包含 ogg-vorbis 标签
- jpeg 文件可以包含 exif 数据
- pdf 文件可以包含各种信息字段
编辑/添加/删除这些标签应该使用专门的库来完成.
Editing/adding/removing those tags should be done with dedicated libraries.
这篇文章有一个很好的解释:
在 Windows 资源管理器中,您可以看到很多文档属性许多文件类型.漂亮、统一的界面表明有一些统一的物业店.事实并非如此.探险家Shell 具有用于属性表处理程序的可扩展接口,从各种文件类型中提取此信息.有一个处理程序用于 JFIF (JPEG) 文件,并且有用于 OLE 文件的处理程序(旧Office 格式),以及新的 Office 格式.
In Windows Explorer you can see quite a lot of document properties for many file types. The nice, unified interface suggests that there is some unified property store. That's not really the case. The Explorer Shell has an extensible interface for Property Sheet Handlers that extract this information from various file types. There is a handler for JFIF (JPEG) files, and there are handlers for OLE files (old Office formats), and the new Office formats too.
还有这个 post显示 OP如何通过ShellFile
成功添加标签.
And this post shows how the OP successfully adds tags via ShellFile
.
另外推荐阅读:获取和设置C#中的文件标签元信息
这篇关于C# - 添加、编辑和删除文件的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!