Where does windows explorer store file meta data?
In Windows 7 I can add meta data to files for example title, rating and so on. Where is this meta data stor开发者_如何学Goed 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?
In Windows 7 I can add meta data to files [using Explorer] for example title, rating and so on. Where is this meta data stored exactly?
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
and IPropertyStore
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:
Gotcha: Many people mistakenly call
StgOpenStorageEx
. Don't do that!StgOpenStorageEx
is only supported for specific formats like OLE Compound Documents or NTFS secondary stream storage.StgOpenStorageEx
doesn't know how to read the EXIF header from a.JPG
image.
Starting with Windows Vista, metadata is now stored inside the file itself.
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
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:
using System;
using Microsoft.WindowsAPICodePack.Shell.PropertySystem;
using Microsoft.WindowsAPICodePack.Shell;
namespace Properties
{
public class PictureFileProperties
{
public string GetCamera(string filename)
{
if (!System.IO.File.Exists(filename))
return null;
ShellObject picture = ShellObject.FromParsingName(filename);
if (picture != null)
{
var manufacturer = picture.Properties.GetProperty(SystemProperties.System.Photo.CameraManufacturer)).Value;
var model = picture.Properties.GetProperty(SystemProperties.System.Photo.CameraModel).Value;
return string.Format("{0} {1}", manufacturer, model);
}
return null;
}
}
}
精彩评论