473,770 Members | 4,522 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting correct version using FileVersionInfo

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
1 6215
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.Tri m().Replace
(",", ".");
fileVersion = fileVersion.Rep lace(" ", "");
string[] versionParts = fileVersion.Spl it('.');
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:
FileVersionInf o fileVersionInfo =
FileVersionInf o.GetVersionInf o(filePath);

string fileVersion = fileVersionInfo .FileVersion;
Sometimes though, I get versions that look like "5.2.02.2WestNileBuil d" 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
22488
by: Frank T. Clark | last post by:
I am having trouble trying to retrieve the version resources of the executing assembly at runtime. I want to retrieve AssemblyTitle, AssemblyDescription, AssemblyCompany, AssemblyProduct, and AssemblyCopyright.I assume it has something to do with GetExecutingAssembly. What am I missing? A line or two of sample code is greatly appreciated. Thank you.
2
9811
by: jwexqm | last post by:
I'm using a COM DLL from a C# application via an interop wrapper generated by 'tlbimp.exe'. That all works fine, I can fire off methods and things happen as they should. My issue is that I want my application to check both that the COM DLL is registered on the system and its version is acceptable. I envisage a bit of code at the beginning of the application's runtime that performs these checks. I've got a 'soup' of ideas about how to...
2
56956
by: kris | last post by:
Hello, We're porting some old code to our new C# .NET project and are having trouble getting the file version of a non-.NET EXE file using C# .NET code. In our old code, we were using the FileSystemObject (specifically the GetFileVersion method) to easily get the version of the EXE file. In .NET however, we haven't been able to figure out an equivalent method to easily get the file version of a non-.NET file.
5
43307
by: Paul Horn | last post by:
Hi I need some help here. I would appreciate it if any one can help me. My 2 questions is this: 1. How do you get a list of installed applications on Windows? 2. How do I get a program's description from a exe? (Example - sqlservr.exe = Microsoft SQL Server 2000) I am using C# with Visual Studio .net 2003. Thanks in advance...
2
2626
by: Robert | last post by:
I have an application migrated from 1.1 to 2.0 via VS2005. Under 1.1 I could do the following to return the version information (as found in the assemblyinfo.vb file) GetVersion = System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly.Location).FileMajorPart.ToString + "." +...
5
1406
by: Brian Henry | last post by:
If you want to read in the description/version/copyright of a file (any not necessarly a .NET one) how would you do this? I just want to list all the files in a directory and their version numbers if they have one thanks
0
1582
by: Grant_Sutty | last post by:
Hi The only file information I need to access for a bunch of files (dlls & exe) on several remote servers is "file version number". Using the code below, I appear to be able to access all information (properties) other than file version - using (System.Management Namespace - WMI). Can anyone assist me how to access file version. I see that for a local PC, one can use the System.Diagnositcs.FileVersionInfo class (rather than simply the...
4
1607
by: =?Utf-8?B?U2hhcm9u?= | last post by:
How can I read the version of an existing file? The file I checking is a COM dll file. ------- Thanks Sharon
2
4833
by: =?Utf-8?B?Unlhbg==?= | last post by:
I am using vb.net to launch an external application (.exe); how do I capture this external applications's version number in my vb.net app?
0
9602
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10237
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10071
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9882
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5326
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5467
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3589
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2832
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.