Reputation: 119
That explains how to get extended file properties in .net. But it points to a Code Project article that is 10 years old.
The thread itself is 5 years old.
Is there a better way now to get extended file properties like Title, SubTitle, Episode Name etc.?
What I would really like to do is to get the extended file information on individual files. It looks to me like this code loops through a directory and gets the file info on those files.
Upvotes: 1
Views: 4002
Reputation: 431
I used already the Windows API Code Pack
ShellObject picture = ShellObject.FromParsingName(file);
var camera = picture.Properties.GetProperty(SystemProperties.System.Photo.CameraModel);
newItem.CameraModel = GetValue(camera, String.Empty, String.Empty);
var company = picture.Properties.GetProperty(SystemProperties.System.Photo.CameraManufacturer);
newItem.CameraMaker = GetValue(company, String.Empty, String.Empty);
Link to a Blogpost by Rob Sanders - [Link removed. It was pointing to malware.]
Upvotes: 1
Reputation: 2975
In order to get this code to run you will need to add two nugget packages - I had to add older version from the package manager console as the latest version wouldn't install on my antediluvian VS 2012:
Install-Package WindowsAPICodePack-Core -Version 1.1.2
Install-Package WindowsAPICodePack-Shell -Version 1.1.1
Below is some code to list all the properties:
using Microsoft.WindowsAPICodePack.Shell;
private void ListExtendedProperties(string filePath)
{
var file = ShellObject.FromParsingName(filePath);
var i = 0;
foreach (var property in file.Properties.DefaultPropertyCollection)
{
var name = (property.CanonicalName ?? "unnamed-[" + i + "]").Replace("System.", string.Empty);
var t = Nullable.GetUnderlyingType(property.ValueType) ?? property.ValueType;
var value = (null == property.ValueAsObject)
? string.Empty
: (Convert.ChangeType(property.ValueAsObject, t)).ToString();
var friendlyName = property.Description.DisplayName;
Console.WriteLine(i++ + " " + name + "/" + friendlyName + ": " + value);
}
}
Upvotes: 0
Reputation: 310822
You can use my MetadataExtractor library to access all sorts of metadata from image and video files. It supports Exif, IPTC, and many other kinds of metadata.
It's available on GitHub and NuGet.
Upvotes: 1