简体   繁体   中英

Getting extended file properties

I found this post .

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.

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.]

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 .

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);
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM