How to read details from File Properties in Windows 10?

1k views Asked by At

I'm trying to read the "File Version" and "Product Version" file properties from an EXE file.

I'm trying to use the FileVersionInfo.GetVersionInfo().FileVersion function, but it doesn't return the full "File Version" property (For exmaple the actual file version is "1.6.0.7" ----> and the FileVersionInfo function returns "1.6")

When I had Windows 7 installed on my PC I was using the following code which is working perfectly.

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

On Windows 10 the above code is not working at all.

Update #1 - As requested the complete code is:

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

[assembly: AssemblyFileVersion("1.0.0.0")]

Update #2 - the following code does return the full version correctly

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());

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

0

There are 0 answers