在.Net Core中获取文件扩展属性
我想使用.Net Core
从文件中读取扩展属性,如Product Version
,Author
等。在.Net Core中获取文件扩展属性
有类,如FileVersionInfo
是用来提供版本信息,Shell对象阅读更多有关文件等
现在,我不觉得这样的课了。如何使用.Net Core
阅读这些信息?
也许你可以通过FileInfo对象使用文件信息提供到.NET的核心..
IFileProvider provider = new PhysicalFileProvider(applicationRoot);
IDirectoryContents contents = provider.GetDirectoryContents(""); // the applicationRoot contents
IFileInfo fileInfo = provider.GetFileInfo("wwwroot/js/site.js"); // a file under applicationRoot
迭代...
看到更多的公...
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/file-providers
希望它有帮助..
它提供了基本的FileInfo,不提供扩展属性 – Hitesh
FileVersionInfo
可NuGet很容易被发现,它被定位从一开始就 System.Diagnostics
命名空间,所以你只需要安装的软件包:
Install-Package System.Diagnostics.FileVersionInfo
,并使用这个类像往常一样,getting the file info一些IFileProvider
,例如, 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
信息,你应该使用FileSecurity
类,它位于System.Security.AccessControl
命名空间,与System.Security.Principal.NTAccount
类型:
Install-Package System.Security.AccessControl
Install-Package System.Security.Principal
后用法是相似的:现在
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
它,所以你一定会得到所需要的文件与它的新位置。
https://www.nuget.org/packages/System.IO.FileSystem/ – CodeCaster
它包含FileInfo类,它提供了基本信息,而不是扩展属性 – Hitesh