方案一:使用微乳封装的Shell包

添加nuget包:Microsoft.WindowsAPICodePack.Shell


using Microsoft.WindowsAPICodePack.Shell;
using Microsoft.WindowsAPICodePack.Shell.PropertySystem;
1    string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "需求文档_迭代版_036.docx");
var file = ShellFile.FromFilePath(filePath); //Read and Write: string[] oldAuthors = file.Properties.System.Author.Value;
string oldTitle = file.Properties.System.Title.Value;
var orgAppName = file.Properties.System.ApplicationName; file.Properties.System.Author.Value = new string[] { "Author #1", "Author #2" };
file.Properties.System.Title.Value = "Example Title"; // Alternate way to Write: ShellPropertyWriter propertyWriter = file.Properties.GetPropertyWriter();
propertyWriter.WriteProperty(SystemProperties.System.Author, new string[] { "Author" });
propertyWriter.Close();

2  直接使用Shell32交互

添加Com组件引用:

             List<string> arrHeaders = new List<string>();
List<Tuple<int, string, string>> attributes = new List<Tuple<int, string, string>>(); Shell32.Shell shell = new Shell32.Shell();
var strFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "需求文档_迭代版_036.docx"); Shell32.Folder objFolder = shell.NameSpace(System.IO.Path.GetDirectoryName(strFileName));
Shell32.FolderItem folderItem = objFolder.ParseName(System.IO.Path.GetFileName(strFileName)); for (int i = ; i < short.MaxValue; i++)
{
string header = objFolder.GetDetailsOf(null, i);
if (String.IsNullOrEmpty(header))
break;
arrHeaders.Add(header);
} // The attributes list below will contain a tuple with attribute index, name and value
// Once you know the index of the attribute you want to get,
// you can get it directly without looping, like this:
var Authors = objFolder.GetDetailsOf(folderItem, ); for (int i = ; i < arrHeaders.Count; i++)
{
var attrName = arrHeaders[i];
var attrValue = objFolder.GetDetailsOf(folderItem, i);
var attrIdx = i; attributes.Add(new Tuple<int, string, string>(attrIdx, attrName, attrValue)); Debug.WriteLine("{0}\t{1}: {2}", i, attrName, attrValue);
}
Console.ReadLine();

参考资料:

https://stackoverflow.com/questions/37869388/how-to-read-extended-file-properties-file-metadata

https://stackoverflow.com/questions/220097/read-write-extended-file-properties-c/2096315#2096315

https://stackoverflow.com/questions/24081665/windows-api-code-pack-where-is-it

https://www.codeproject.com/Articles/5036/ID3-Tag-Reader-Using-Shell-Functions

Windows API Code Pack 1.1.zip

https://github.com/jamie-pate/KeepSync/blob/master/contrib/Windows%20API%20Code%20Pack%201.1.zip

最新文章

  1. java中transient关键字的作用
  2. Symbol not found for architecture arm64 错误
  3. 回车与换行 ---编码等相关讨论----由notepad++ 批量替换 引发的讨论,转义字符也是人为硬性规定的。
  4. 【tips】判断两个整数是否是同一个数量级
  5. ClassNotFoundException异常的解决方法
  6. redis提示Could not get a resource from the pool(jedis连接池配置)
  7. [改善Java代码]构造代码块会想你所想
  8. StorSimple 简介
  9. 如何断开eclipse与svn的链接
  10. Scala-的元组和映射
  11. centos防火墙端口配置
  12. PHP SPL他们留下的宝石
  13. php用魔术方法__call实现类函数重载
  14. MVC TO LINQ
  15. php数组合并,反转,去重,添加元素等;
  16. nginx简单安装设置
  17. C#反射详解
  18. 使用Swagger 搭建高可读性ASP.Net WebApi文档
  19. JS中的跨域问题
  20. MySQL查询实例

热门文章

  1. Nginx proxy_set_header
  2. C#MongDB数据库取某时间段内的数据
  3. 部署http访问SVN模式出现403问题
  4. Spring IOC 总结
  5. Mysql 单表查询where初识
  6. 关于何时执行shiro AuthorizingRealm 里的 doGetAuthenticationInfo与doGetAuthorizationInfo
  7. hive自定义函数学习
  8. OpenStack核心组件-cinder存储服务
  9. PHP开启慢日志查询
  10. 使用Xpath+多进程爬取诗词名句网的史书典籍类所有文章。update~