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#