我想使用.Net Core
從文件中讀取擴展屬性,如Product Version
,Author
等。在.Net Core中獲取文件擴展屬性
有類,如FileVersionInfo
是用來提供版本信息,Shell對象閱讀更多有關文件等
現在,我不覺得這樣的課了。如何使用.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