如何从Windows 10中的文件属性中读取详细信息?

时间:2017-09-12 16:21:38

标签: c# properties fileversioninfo

我试图阅读"文件版本"和"产品版本"来自EXE文件的文件属性。

我尝试使用FileVersionInfo.GetVersionInfo().FileVersion功能,但它没有返回完整的"文件版本" property(例如,实际文件版本  是" 1.6.0.7" ---->并且FileVersionInfo函数返回" 1.6")

当我在我的电脑上安装了Windows 7时,我正在使用以下代码,该代码运行正常。

Shell shell = new Shell();
Folder objFolder = shell.NameSpace(Path.GetDirectoryName(strFileName));
FolderItem folderItem = objFolder.ParseName(Path.GetFileName(strFileName));
string fileversion = objFolder.GetDetailsOf(folderItem, 156)

在Windows 10上,上述代码根本无效。

更新#1 - 根据要求,完整代码为:

string fileversion = FileVersionInfo.GetVersionInfo(@"E:\NewFolder\file.exe").FileVersion;

[assembly:AssemblyFileVersion(" 1.0.0.0")]

更新#2 - 以下代码确实正确返回完整版

FileVersionInfo fvi = FileVersionInfo.GetVersionInfo("C:\\MyFile.txt");
int major = fvi.ProductMajorPart;
int minor = fvi.ProductMinorPart;
int build = fvi.ProductBuildPart;
int revsn = fvi.ProductPrivatePart;
string q = String.Concat(major.ToString(), ".", minor.ToString(), ".", build.ToString(), ".", revsn.ToString());

来源:Getting the program version of an executable file like explorer does in C# .NET 2

0 个答案:

没有答案
相关问题