【问题标题】:Getting extended file properties获取扩展文件属性
【发布时间】:2013-10-09 00:44:31
【问题描述】:

I found this post.

这解释了如何在 .net 中获取扩展文件属性。但它指向了一篇已有 10 年历史的 Code Project 文章。

线程本身已有 5 年历史。

现在有没有更好的方法来获取标题、子标题、剧集名称等扩展文件属性?

我真正想做的是获取单个文件的扩展文件信息。在我看来,这段代码循环遍历一个目录并获取这些文件的文件信息。

【问题讨论】:

  • 该线程中的代码是否有效?

标签: c# .net c#-4.0


【解决方案1】:

我已经使用了 Windows API 代码包

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

Rob Sanders 的博文链接 - [链接已删除。它指向恶意软件。]

【讨论】:

  • 还有一个 NuGet-Package WindowsAPICodePack-Core
  • 博文的链接现在会随机重定向到充满欺骗性下载链接的可疑页面...
【解决方案2】:

您可以使用我的MetadataExtractor 库来访问图像和视频文件中的各种元数据。它支持 Exif、IPTC 和许多其他类型的元数据。

GitHubNuGet 上可用。

【讨论】:

    【解决方案3】:

    为了运行此代码,您需要添加两个 nugget 包 - 我必须从包管理器控制台添加旧版本,因为最新版本不会安装在我的 antediluvian VS 2012 上:

        Install-Package WindowsAPICodePack-Core -Version 1.1.2
        Install-Package WindowsAPICodePack-Shell -Version 1.1.1
    

    下面是列出所有属性的一些代码:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-03-11
      • 2016-07-13
      • 1970-01-01
      • 2018-07-08
      • 1970-01-01
      • 1970-01-01
      • 2016-01-15
      相关资源
      最近更新 更多