C# 在.Net Core中获取文件扩展属性

C# 在.Net Core中获取文件扩展属性,c#,file,asp.net-core,.net-core,C#,File,Asp.net Core,.net Core,我想使用.Net Core从文件中读取扩展属性,如产品版本,作者等 有像FileVersionInfo这样的类用来提供版本信息,Shell对象用来阅读更多关于文件的信息,等等 现在,我再也找不到这样的课程了。我如何使用.Net Core读取此类信息?也许您可以将文件信息提供程序用于.Net Core IFileProvider provider = new PhysicalFileProvider(applicationRoot); IDirectoryContents contents = p

我想使用
.Net Core
从文件中读取扩展属性,如
产品版本
作者

有像
FileVersionInfo
这样的类用来提供版本信息,Shell对象用来阅读更多关于文件的信息,等等


现在,我再也找不到这样的课程了。我如何使用
.Net Core
读取此类信息?

也许您可以将文件信息提供程序用于.Net Core

IFileProvider provider = new PhysicalFileProvider(applicationRoot);
IDirectoryContents contents = provider.GetDirectoryContents(""); // the applicationRoot contents
IFileInfo fileInfo = provider.GetFileInfo("wwwroot/js/site.js"); // a file under applicationRoot
遍历
fileInfo
对象

有关更多信息,请参见此:


希望有帮助。

FileVersionInfo
可以在上找到,它位于 命名空间,因此您只需安装包:

Install-Package System.Diagnostics.FileVersionInfo
并像往常一样使用这个类,例如,从一些
PhysicalFileProvider

using System.Diagnostics;

var provider = new PhysicalFileProvider(applicationRoot);
// the applicationRoot contents
var contents = provider.GetDirectoryContents("");
// a file under applicationRoot
var fileInfo = provider.GetFileInfo("wwwroot/js/site.js");
// version information
var myFileVersionInfo = FileVersionInfo.GetVersionInfo(fileInfo.PhysicalPath);
//  myFileVersionInfo.ProductVersion is available here
对于
Author
信息,您应该使用位于命名空间中的类,类型为:

在此之后,用法类似:

using System.Security.AccessControl;
using System.Security.Principal;

var fileSecurity = new FileSecurity(fileInfo.PhysicalPath, AccessControlSections.All);
// fileSecurity.GetOwner(typeof(NTAccount)) is available here

现在的一般规则是用谷歌搜索一个类的完整限定名,然后将
core
nuget
添加到该类中,这样你肯定会在新位置获得所需的文件。

它包含提供基本信息的FileInfo类,而不是扩展属性什么“扩展属性”是否要准确读取?元数据属性-在Windows中右键单击“文件”、“属性”、“详细信息”时。在那里添加我自己的属性和值。@JohanFoley-这是许多内容的复合视图,您不能在任何情况下添加自己的属性。它提供基本的文件信息,不提供扩展属性
using System.Security.AccessControl;
using System.Security.Principal;

var fileSecurity = new FileSecurity(fileInfo.PhysicalPath, AccessControlSections.All);
// fileSecurity.GetOwner(typeof(NTAccount)) is available here