By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,307 Members | 1,604 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,307 IT Pros & Developers. It's quick & easy.

Getting correct version using FileVersionInfo

P: n/a
Jim
Hi. I would like to validate the version string that I
get from FileVersionInfo. Is there a way via the object
model to do this?

I am currently doing this:
FileVersionInfo fileVersionInfo =
FileVersionInfo.GetVersionInfo(filePath);

string fileVersion = fileVersionInfo.FileVersion;
Sometimes though, I get versions that look like "5.2.02.2
WestNileBuild" or others that look like "5,2,3,0"

Is there a way to format whatever result I get, to look
like one of the following formats:

1
1.1
1.1.1
1.1.1.1
Thanks

Jim
Nov 13 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Jim
I am using this method to determine if it is a valid
version or not. Is there a cleaner way?

private bool IsVersion(ref string fileVersion)
{
// For cases of 5,5,2,2
fileVersion = fileVersion.Trim().Replace
(",", ".");
fileVersion = fileVersion.Replace(" ", "");
string[] versionParts = fileVersion.Split('.');
bool result = true;

foreach (string versionPart in versionParts)
{
try
{
int iVersionPart = Convert.ToInt32
(versionPart);
}
catch (Exception)
{
result = false;
break;
}
}
return result;
}

-----Original Message-----
Hi. I would like to validate the version string that I
get from FileVersionInfo. Is there a way via the object
model to do this?

I am currently doing this:
FileVersionInfo fileVersionInfo =
FileVersionInfo.GetVersionInfo(filePath);

string fileVersion = fileVersionInfo.FileVersion;
Sometimes though, I get versions that look like "5.2.02.2WestNileBuild" or others that look like "5,2,3,0"

Is there a way to format whatever result I get, to look
like one of the following formats:

1
1.1
1.1.1
1.1.1.1
Thanks

Jim
.

Nov 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.