方案一:使用微乳封装的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

C# 获取文件扩展信息-应用名称/作者等的更多相关文章

  1. Web 在线文件管理器学习笔记与总结(11)获取文件夹信息 (12)返回上一级操作

    (11)获取文件夹信息 文件夹没有修改操作. index.php: <?php require 'dir.func.php'; require 'file.func.php'; require ...

  2. PHP获取文件扩展名的多种方法

    PHP获取文件扩展名的N种方法. 第1种方法: function get_extension($file) { substr(strrchr($file, '.'), 1): } 第2种方法: fun ...

  3. python获取文件扩展名的方法(转)

    主要介绍了python获取文件扩展名的方法,涉及Python针对文件路径的相关操作技巧.具体实现方法如下: 1 2 3 4 import os.path def file_extension(path ...

  4. python获取文件扩展名的方法

    主要介绍了python获取文件扩展名的方法,涉及Python针对文件路径的相关操作技巧 import os.path def file_extension(path): ] print file_ex ...

  5. 如何去掉drwxr-xr-x@中的@符号Linux文件扩展信息

    如何去掉drwxr-xr-x@中的@符号Linux文件扩展信息ls -lart drwxrwxrwx@ 10 rlanffy staff 340B 3 6 2015 files-rwxrwxrwx@ ...

  6. Powershell 获取文件版本信息

    获取文件版本信息,通过FileVersionInfo::GetVersioninfo(file) 来获取信息 function Check-DdpstoreFileVersion{ $Ddpstore ...

  7. PHP中获取文件扩展名的N种方法

    PHP中获取文件扩展名的N种方法 从网上收罗的,基本上就以下这几种方式: 第1种方法:function get_extension($file){substr(strrchr($file, '.'), ...

  8. os.path.join合并 os.path.dirname返回上一级目录 os.path.exists(path) os.stat('path/filename')获取文件/目录信息

    import os str1 = "grsdgfd" str2 = "wddf" str3 = "gddgs" # print(str1 + ...

  9. PHP获取文件扩展名五种以上的方法和注释

    在PHP面试中或者考试中会有很大几率碰到写出五种获取文件扩展名的方法,下面是我自己总结的一些方法 $file = ‘需要进行获取扩展名的文件.php’; //第一种,根据.拆分,获取最后一个元素的值f ...

随机推荐

  1. list集合排序案例

    // List集合排序: Collections.sort(list, new Comparator<Object>(){ public int compare(Object obja, ...

  2. maven学习笔记五(仓库搭建,私服配置)

    实际项目中,我们往往都是多人开发,这个时候,假如一个项目有300多M.用的jar包有100多个.只要项目组来一个人就从中央仓库下载依赖的jar,这种下载一般都需要持续很久.而且中央仓库一般都是配置在外 ...

  3. Kubernetes pod平滑迁移

    pod平滑迁移 使用到的命令 (cordon, drain, uncordon)这三个命令是正式release的1.2新加入的命令,三个命令一起介绍,是因为三个命令配合使用可以实现节点的维护.在1.2 ...

  4. Zabbix Documentation 4.0

    Zabbix Documentation 4.0 1 Create user account For all of the Zabbix daemon processes, an unprivileg ...

  5. js 判断浏览器是pc端还是移动端

    if(/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) { //说明是移动端 } else { //说明是pc端 }

  6. 51nod 2489 小b和灯泡

    小b有n个关闭的灯泡,编号为1...n. 小b会进行n轮操作,第i轮她会将编号为i的倍数的灯泡的开关状态取反,即开变成关,关变成开. 求n轮操作后,有多少灯泡是亮着的. 收起   输入 输入一个数字表 ...

  7. 51nod1712 区间求和

    http://www.51nod.com/Challenge/Problem.html#problemId=1712 先考虑题面中的简化问题. 对于\(i\in [1,n]\),\(a_i\)的贡献为 ...

  8. 《基于 Web Service 的学分制教务管理系统的研究与实现》论文笔记(十一)

    标题:基于 Web Service 的学分制教务管理系统的研究与实现 一.基本内容 时间:2014 来源:苏州大学 关键词:: 教务管理系统 学分制 Web Service 二.研究内容 1.教务管理 ...

  9. makefile的三个变量

    “$@”代表目标文件. “$^”代表所有的依赖文件. “$<”代表第一个依赖文件. main:main.o mytool1.o mytool2.o gcc -o $@ $^ .c.o: gcc ...

  10. Dubbo源码分析:Serialization

    背景 顺序化逻缉处理! 类图 获取Serialization对象时序图 序列化