Alan
Alan

Reputation: 23

Incorrect format when converting FileVersion ToDouble

I am making a small program that downloads files from internet, depending on the file version of another file.

Here is some of the code (where I am getting an error):

XmlDocument xdoc = new XmlDocument();
xdoc.Load("http://raiderz.daregamer.com/updates/app_version.xml");
XmlNodeList xNodeVer = xdoc.DocumentElement.SelectNodes("Version");
FileVersionInfo fileVer = FileVersionInfo.GetVersionInfo(AppDomain.CurrentDomain.BaseDirectory + "FileCheckVer.exe");
double ver_app = Convert.ToDouble(fileVer.FileVersion.ToString());
double ver_xml = Convert.ToDouble(xNodeVer);

The error says, "Input string was not in a correct format." and points to the following line.

double ver_app = Convert.ToDouble(fileVer.FileVersion.ToString());

Does anyone know what the correct format is?

Thanks!

Upvotes: 1

Views: 305

Answers (2)

DaveShaw
DaveShaw

Reputation: 52798

A FileVersion is in the Format d.d.d.d (2.0.0.0), where a double is just a floating point number (d.d).

All the information you need is in the FileVersionInfo instance you already created (check the properties).

/EDIT

Answer to Q2. You need to use SelectSingleNode() to return an XmlNode, then you look at the .Value property of that.

Upvotes: 0

Jon Skeet
Jon Skeet

Reputation: 1500855

It's a four part number, e.g. 1.2.3.4. What double value did you expect to get out of that?

If you want to get at each of the bits of it, then rather than converting it to a string and then trying to parse it, just use FileVersionInfo properties such as FileMajorPart etc.

Upvotes: 2

Related Questions