Question

I'm attempting to use C# and System.Diagnostics.FileVersionInfo to extract the version information from a list of files. My purpose for doing this is to keep track of unique filepath and version combinations. When the files change I'd like various things to happen depending on what exactly changed.

I've used both the FileVersion and ProductVersion properties of FileVersionInfo to no avail. Both report a different version number than what is reported in explorer.

An example using explorer.exe

Explorer Details tab reports: "6.1.7601.17567" (for both File and Product)
FVI.ProductVersion reports: "6.1.7600.16385"
FVI.FileVersion reports: "6.1.7600.16385 (win7_rtm.090713-1255)"
Was it helpful?

Solution

For some reason the ProductVersion property doesn't match the ProductMajorPart/MinorPart/BuildPart/PrivatePart... To get the actual version you can do this:

var fvi = FileVersionInfo.GetVersionInfo(path);
var productVersion = new Version(
                           fvi.ProductMajorPart,
                           fvi.ProductMinorPart,
                           fvi.ProductBuildPart,
                           fvi.ProductPrivatePart);
var fileVersion = new Version(
                           fvi.FileMajorPart,
                           fvi.FileMinorPart,
                           fvi.FileBuildPart,
                           fvi.FilePrivatePart);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top