Getting correct version using FileVersionInfo

J

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
 
J

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;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top