2

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

Dorel
  • 103
  • 12
  • 4
    Does this help? https://stackoverflow.com/questions/11350008/how-to-get-exe-file-version-number-from-file-path – Equalsk Sep 12 '17 at 16:23
  • 2
    Possible duplicate of [How to get .exe file version number from file path](https://stackoverflow.com/questions/11350008/how-to-get-exe-file-version-number-from-file-path) – Sir Rufo Sep 12 '17 at 16:32
  • @Equalsk those answers don't help me. – Dorel Sep 12 '17 at 17:38
  • Post your complete version code (and AssemblyFileVersion) including printing the file version. Something is likely wrong with your code. GetVersionInfo().FileVersion returns complete information. – Ton Plooij Sep 12 '17 at 19:43
  • @Dorel I don't believe you tried it properly, I can guarantee the code in the linked answer works perfectly fine on Windows 10 and returns a full version number of any exe. – Equalsk Sep 12 '17 at 21:08
  • @Ton Plooij as requested I have updated the question. – Dorel Sep 13 '17 at 05:14
  • What does `fvi.ProductVersion` show compared to your string concatenation? – Equalsk Sep 13 '17 at 08:11
  • fvi.ProductVersion show the same result as fvi.FileVersion. For exmaple the actual file version is "1.6.0.7" ----> and the FileVersionInfo/ProductVersion function returns "1.6". problem solved. – Dorel Sep 13 '17 at 17:40

0 Answers0