Click here to Skip to main content
15,891,758 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi everyone!

I am having trouble converting the FileVersionInfo.GetVersionInfo number to a double. I need to compare it to a number to alert the user that the 3rd party program is out of date.

Here is what I have so far:

FileVersionInfo psVersionInfo = FileVersionInfo.GetVersionInfo(process);
// This will get the version of the program.

I've tried Convert.ToDouble(psVersionInfo) and that doesn't work. The version number is in the form of "6.6.54".

Can someone shed some light as to what I'm missing?

Thanks everyone!
Posted
Comments
Prasad Khandekar 26-Mar-13 15:44pm    
It's not really a number. If you want to compare remove all dots and then convert it into double.
Steve Wellens 26-Mar-13 15:47pm    
Even if it was a double (and it's not) comparing doubles requires tolerance handling because 1.000000000000 does not equal 1.00000000000001 (even though they are practically the same number).
André Kraak 26-Mar-13 15:47pm    
What is this number you want to compare the FileVersionInfo with?
How did you get it?
joshrduncan2012 26-Mar-13 15:51pm    
The 6.6.54 is the current build of the program we want to check for up-to-date.
joshrduncan2012 26-Mar-13 15:52pm    
I wanted to compare it with like 6.6.52 (or something like that).

Have a look at Darren Kopp's answer, here ... http://stackoverflow.com/questions/30494/compare-version-identifiers[^]

'g'
 
Share this answer
 
Better converting not to double but to DWORD or ULONGLONG (in .NET it uint and ulong).
And make high version part to be at high bit order so you can compare that 2 numbers only.
In .NET it will looks:
C#
public uint GetVersion(string _version)
{
    uint uiVersion = 0;
    string[] aVersion = _version.Split('.');
    for (int i = 0; i < aVersion.Length; i++)
    {
        uiVersion += (uint.Parse(aVersion[i]) << (8 * (aVersion.Length - i - 1)));
    }
    return uiVersion;
}

And the usage:
C#
uint uiVersion1 = GetVersion("6.2.54");
uint uiVersion2 = GetVersion("6.2.52");
if (uiVersion1 > uiVersion2)
{
    // First version higher
}
if (uiVersion1 < uiVersion2)
{
    // Second version higher
}
if (uiVersion1 == uiVersion2)
{
    // Versions are equals
}

Regards,
Maxim.
 
Share this answer
 
As far as I am aware a FileVersionInfo cannot be converted to a double that simply. The ToString() method will return an incorrect format. Trying to parse it using Double.Parse("6.6.54") will throw an exception, which is basically what Convert.ToDouble() will try and do.
 
Share this answer
 
If you want to compare two version numbers the most robust way would be to compare each part of the number separately.

The version is build up like this:
Typically, a version number is displayed as "major number.minor number.build number.private part number". A product version number is a 64-bit number that holds the version number as follows:

The first 16 bits are the ProductMajorPart[^] number.
The next 16 bits are the ProductMinorPart[^] number.
The third set of 16 bits are the ProductBuildPart[^] number.
The last 16 bits are the ProductPrivatePart[^] number.
So if the ProductMajorPart[^] is smaller the version is older, but if it is the same you should continue to check the ProductMinorPart[^], etc.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900