C# - 添加,编辑和删除文件的标签 [英] C# - Add, edit and delete tags of file

查看:256
本文介绍了C# - 添加,编辑和删除文件的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在文件系统中添加和检索文件的标签。

正如你可以将Stackoverflow问题标记为相关主题,你可以在Windows文件系统中标记一个文件:



以下方法不能访问文件的标签,而只能访问其他文件属性。 / p>

  string file = @C:\Users\me\Desktop\MyFile.doc; 

FileInfo oFileInfo = new FileInfo(file);
MessageBox.Show(oFileInfo.FullName);

使用简单的API System.IO

解决方案


正如你可以标记Stackoverflow问题的相关主题,你可以
在Windows文件系统中标记一个文件

这个假设是错误的。您不能将标签添加到所有文件类型。请参阅此处


注意

您不能添加或修改文件属性某些类型的文件。
例如,您可以添加或修改Microsoft
Office文档和搜索的属性,但不能添加或修改TXT或RTF文件的
属性。


除了上面提到的类型,还有其他可以包含自定义标签的类型:


  • mp3文件可以包含各种版本的ID3标签

  • flac和ogg文件可以包含ogg-vorbis标签

  • jpeg文件可以包含exif数据

  • pdf文件可以包含各种信息字段



编辑/添加/使用专用的库。



这篇文章有一个很好的解释:

lockquote
在Windows资源管理器中,您可以看到许多文件属性为
许多文件类型。好的,统一的界面表明,有一个统一的地产商店
。事实并非如此。资源管理器
Shell有一个可扩展的接口,用于
从各种文件类型中提取这些信息。 JFIF(JPEG)文件有一个处理程序
,并且有OLE文件的处理程序(旧的
Office格式)和新的Office格式。




而且 post shows OP如何通过 ShellFile 成功添加标签。



还推荐阅读:在C#中获取和设置文件标签元信息


I would like to add and retrieve tags of files in File System.

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:\Users\me\Desktop\MyFile.doc";

FileInfo oFileInfo = new FileInfo(file);
MessageBox.Show(oFileInfo.FullName);

Any ideas how to access the tags using the simple API of System.IO?

解决方案

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:

Note

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 files can contain ID3 tag of various versions
  • flac and ogg files can contain ogg-vorbis tags
  • jpeg files can contain exif data
  • pdf files can contain various info fields

Editing/adding/removing those tags should be done with dedicated libraries.

This post has a nice explanation:

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.

And this post shows how the OP successfully adds tags via ShellFile.

Also recommended reading: Getting and Setting File Tag Meta Information in C#

这篇关于C# - 添加,编辑和删除文件的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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