Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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 26-Mar-13 10:32am
Comments
Prasad Khandekar at 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 at 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 at 26-Mar-13 15:47pm
   
What is this number you want to compare the FileVersionInfo with?
How did you get it?
joshrduncan2012 at 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 at 26-Mar-13 15:52pm
   
I wanted to compare it with like 6.6.52 (or something like that).
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Have a look at Darren Kopp's answer, here ... http://stackoverflow.com/questions/30494/compare-version-identifiers[^]
 
'g'
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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:
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:
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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 390
1 Sergey Alexandrovich Kryukov 329
2 Afzaal Ahmad Zeeshan 244
3 BillWoodruff 210
4 Maciej Los 192
0 OriginalGriff 5,560
1 DamithSL 4,476
2 Maciej Los 3,942
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,175


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 27 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100