I have an exe file simpleservice.exe in the physical path F:\SAMPLEPRODUCT\Bin ,, i need to fetch version number of that exe file,,Can you give the code required to fetch the version number
Asked
Active
Viewed 445 times
1
-
What language is simpleservice.exe written in? – Ian Kemp Sep 07 '09 at 08:25
-
http://stackoverflow.com/questions/1111541/how-to-reference-both-assemblyversion-and-assemblyfileversion – Preet Sangha Sep 07 '09 at 08:25
-
Or if you just want to see it in explorer? Then right click and go to properties | details. – Preet Sangha Sep 07 '09 at 08:27
6 Answers
5
You can use
FileVersionInfo.GetVersionInfo
for this
Eg:
public void GetFileVersion() {
// Get the file version for the exe.
FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo("your_exe_file");
// Print the file name and version number.
textBox1.Text = "File: " + myFileVersionInfo.FileDescription + '\n' +
"Version number: " + myFileVersionInfo.FileVersion;
}

rahul
- 184,426
- 49
- 232
- 263
-
+1 though won't this only work on the assumption the assembly was generated with fileversion and assemblyversion set to the same thing? – Neil Barnwell Sep 07 '09 at 08:28
3
I'd use the following to do this:
Assembly.LoadFrom("...").GetName().Version.ToString();
or I'd use the FileVersionInfo class. Take your pick:
FileVersionInfo.GetVersionInfo("...");

Pete OHanlon
- 9,086
- 2
- 29
- 28
-
I'd accidentally hit submit and not finished typing in the rest of my comment. I re-edited it to show the bit I missed when I clicked Submit. – Pete OHanlon Sep 07 '09 at 08:30
-
here inside Assembly.LoadFrom("...") what we need to give physical path of exe or ? – peter Sep 07 '09 at 08:33
-
OK... I would remove the down vote, but there seems to be a bug... "Vote too old to be changed, unless this answer is edited". Sorry :S – Thomas Levesque Sep 07 '09 at 08:33
-
No problem Thomas - I'm not answering them for the votes, so I'm not upset. I really need to remap the hotkeys on my keyboard to prevent these accidental submits - it's the third time I've done this in a couple of days. – Pete OHanlon Sep 07 '09 at 08:44
-
2
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(@"F:\SAMPLEPRODUCT\Bin\simpleservice.exe");
Console.WriteLine(fvi.FileVersion);

Thomas Levesque
- 286,951
- 70
- 623
- 758
-
Is there any other way for finding the location of a file means physical path,,Means here 'simpleservice.exe' is in these physical path F:\SAMPLEPRODUCT\Bin is there any other simple common way for finding path like server.mappath in ASP.NET,because the path will change some times na,if we copy it into different file – peter Sep 07 '09 at 08:52
-
I don't understand your question... You need to know the file location, if you don't the system can't guess it for you... – Thomas Levesque Sep 07 '09 at 09:21
1
AssemblyName anm = AssemblyName.GetAssemblyName(
"c:\\winnt\\microsoft.net\\framework\\v1.0.3705\\mscorlib.dll");
// and show its version
Console.WriteLine(anm.Version.ToString());

Arsen Mkrtchyan
- 49,896
- 32
- 148
- 184
-
yea but he marks the question with winform and C# tag which give me an assumption that he mean .net assembly – Arsen Mkrtchyan Sep 07 '09 at 09:17
1
AssemblyName.GetAssemblyName(@"F:\SAMPLEPRODUCT\Bin\simpleservice.exe").Version

Tadas Šukys
- 4,140
- 4
- 27
- 32
-
Is there any other way for finding the location of a file means physical path,,Means here 'simpleservice.exe' is in these physical path F:\SAMPLEPRODUCT\Bin is there any other simple common way for finding path like server.mappath in ASP.NET,because the path will change some times na,if we copy it into different file – peter Sep 07 '09 at 08:55
-
1
public string AssemblyVersion
{
get
{
return Assembly.GetExecutingAssembly().GetName().Version.ToString();
}
}

MRG
- 3,219
- 1
- 26
- 35