C# 获取文件扩展信息-应用名称/作者等
方案一:使用微乳封装的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# 获取文件扩展信息-应用名称/作者等的更多相关文章
- Web 在线文件管理器学习笔记与总结(11)获取文件夹信息 (12)返回上一级操作
(11)获取文件夹信息 文件夹没有修改操作. index.php: <?php require 'dir.func.php'; require 'file.func.php'; require ...
- PHP获取文件扩展名的多种方法
PHP获取文件扩展名的N种方法. 第1种方法: function get_extension($file) { substr(strrchr($file, '.'), 1): } 第2种方法: fun ...
- python获取文件扩展名的方法(转)
主要介绍了python获取文件扩展名的方法,涉及Python针对文件路径的相关操作技巧.具体实现方法如下: 1 2 3 4 import os.path def file_extension(path ...
- python获取文件扩展名的方法
主要介绍了python获取文件扩展名的方法,涉及Python针对文件路径的相关操作技巧 import os.path def file_extension(path): ] print file_ex ...
- 如何去掉drwxr-xr-x@中的@符号Linux文件扩展信息
如何去掉drwxr-xr-x@中的@符号Linux文件扩展信息ls -lart drwxrwxrwx@ 10 rlanffy staff 340B 3 6 2015 files-rwxrwxrwx@ ...
- Powershell 获取文件版本信息
获取文件版本信息,通过FileVersionInfo::GetVersioninfo(file) 来获取信息 function Check-DdpstoreFileVersion{ $Ddpstore ...
- PHP中获取文件扩展名的N种方法
PHP中获取文件扩展名的N种方法 从网上收罗的,基本上就以下这几种方式: 第1种方法:function get_extension($file){substr(strrchr($file, '.'), ...
- os.path.join合并 os.path.dirname返回上一级目录 os.path.exists(path) os.stat('path/filename')获取文件/目录信息
import os str1 = "grsdgfd" str2 = "wddf" str3 = "gddgs" # print(str1 + ...
- PHP获取文件扩展名五种以上的方法和注释
在PHP面试中或者考试中会有很大几率碰到写出五种获取文件扩展名的方法,下面是我自己总结的一些方法 $file = ‘需要进行获取扩展名的文件.php’; //第一种,根据.拆分,获取最后一个元素的值f ...
随机推荐
- Oracle恢复流程图
本图来自于网络,想当初小麦苗刚开始接触备份恢复的时候,就是靠着这张图来学习的,今天把这张图分享给大家,共勉. ............................................. ...
- Mysql 常见数据类型及约束
Mysql 常见数据类型及约束 最近在跟几个不太懂技术的同事(哈哈, 其实我也不懂), 要整一个数据库项目, 然后前端, 后端, 都没有像样的, 数据输出还不是由我们控制.... 这可难受了, 然后总 ...
- 【Feign调用异常】org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'GET' not supported
一.异常场景描述 明明是post请求,为啥到达服务器后就变成了get请求 2019-05-30 18:07:17.055 [http-nio-10650-exec-4] ERROR c.x.xcaut ...
- influxDB应用及TICK stack
InfluxData平台用于处理度量和事件的时间序列平台,常被称为TICK stack,包含4个组件:Telegraf,influxDB,Chronograf和Kapacitor,分别负责时间序列数据 ...
- 如何利用python教程判断一个 IP 在不在线?
假设今天老板给我们一个任务,让我们判断一下一个 IP 在不在线.我们随手用 python 写一个 ping IP 的代码: import os host = input('请输入要检测的 IP : ' ...
- pyecharts绘制map地图
pyecharts的安装和地图库的安装可以参照 geo绘图:https://www.cnblogs.com/qi-yuan-008/p/12025123.html 直接进入 python的具体使用阶段 ...
- php图片防盗链
利用.htaccess 重写规则防止图片被盗链 2. 找到httpd.conf 打开重写规则 3.
- 洛谷 P1443 马的遍历题解
题目链接:https://www.luogu.org/problem/P1443 题目描述 有一个n*m的棋盘(1<n,m<=400),在某个点上有一个马,要求你计算出马到达棋盘上任意一个 ...
- poj1734 Sightseeing trip(Floyd求无向图最小环)
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> ...
- .gitignore文件配置的内容为:
/target/ !.mvn/wrapper/maven-wrapper.jar ### STS ### .apt_generated .classpath .factorypath .project ...