In Windows 7 I can add meta data to files for example title, rating and so on. Where is this meta data stored exactly? For NTFS they may use alternate data streams but I this meta data also happen to work in FAT32, so how ho they do it? Is there an API to make use of this feature?
相关问题
- Generic Generics in Managed C++
- How to Debug/Register a Permanent WMI Event Which
- the application was unable to start correctly 0xc0
- 'System.Threading.ThreadAbortException' in
- Bulk update SQL Server C#
Windows stores this in COM Structured storage. The implementation is either in the file itself (Office docs support this, or any file format that supports structured storage), or in NTFS itself.
The API is available here: Structured Storage. The interesting function is StgOpenStorageEx.
Here are some details about NTFS implementation: IPropertySetStorage-NTFS File System Implementation
Starting with Windows Vista, metadata is now stored inside the file itself.
Since you're asking about .Net, you can access file properties using the Microsoft.WindowsAPICodePack-Shell library from nuget. It provides a .Net interface to Windows Properties.
An example use of the library is as follows:
This metadata is called properties. It has been available in this way since Windows Vista.
Windows Explorer presents properties in a unified way, which might trick you into thinking that they're all coming from the same shop. But this is not the case.
Properties are exposed to the programmer via an API. (See below.)
Where exactly they're stored is an implementation detail. It depends on the filetype and on the kind of property. For example, filesystem timestamps are exposed as properties. Media file metadata such as EXIF for images or ID3 tags for MP3 is stored in the file itself. Still other metadata might be stored in an XML file accompanying the file whose properties you're inspecting.
So where is it stored? The answer is: It really depends, and you really don't have to worry, nor should you worry. Because, as I said, it is an implementation detail, and as far as programming goes, worrying about implementation details means bypassing the API.
Neither do you have to worry where properties are stored when dealing with them at the API level. See the
IShellItem2
andIPropertyStore
COM interfaces for an entry point.Under the hood, Windows Vista and later versions ship property handlers that know about filetypes and how to read and write their properties. You could write a property handler of your own (using COM) and add it to Explorer (as a so-called shell extension).
The most useful documentation which I've found is Ben Karas' blog entries around the time of the Vista release starting in August 2006. He's done a whole series on the property system. It's a very useful tutorial, and for me using Windows 7, it has worked 100 %.
Don't follow the advice given in another reply on this page to read up about COM Structured Storage. This is only for specific filetypes. In the words of Ben Karas: