65.9K
CodeProject is changing. Read more.
Home

Obtain file properties from shell using ExtraPropertiesProvider class

starIconstarIconstarIconemptyStarIconemptyStarIcon

3.00/5 (2 votes)

Mar 24, 2010

CPOL
viewsIcon

11761

ExtraPropertie...

ExtraPropertiesProvider obtain properties of a file using IShellFolder2, so you can get properties without parsing them yourself. To obtain a property, you need a file and a property key. A list of possible(but not all) property keys can be found in:
  • SummaryInformation
  • DocSummaryInformation
  • ImageSummaryInformation
  • MusicSummaryInformation
  • VideoSummaryInformation
You can use GetCollumnInfo() method to obtain a list of property keys in a specific folder as well.
string file = "c:\yourpicture.bmp";
string ext = PathEx.GetExtension(file);

string imageFilter = ".jpg,.jpeg,.png,.gif,.bmp,.pcx.tiff";

if (imageFilter.IndexOf(ext) != -1)
  foreach (string key in ImageSummaryInformation.PropertyDic.Keys)
  {
     PropertyKey propKey = ImageSummaryInformation.PropertyDic[key];
     Debug.WriteLine("{0} = {1}", key, ExtraPropertiesProvider.GetProperty(file, ref propKey);
  }
This will return all known properties, and their values:
foreach (CollumnInfo col in ExtraPropertiesProvider.GetCollumnInfo(file.Parent))
                if (col.CollumnName != "")
                {
                    PropertyKey propKey = col.PropertyKey;
                    object obj = ExtraPropertiesProvider.GetProperty(file, ref propKey);
                    if (obj != null)
                        Console.WriteLine(col.CollumnName + " - " + obj.ToString());
                }