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
+5
A:
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
2009-09-07 08:25:31
+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
2009-09-07 08:28:48
+2
A:
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(@"F:\SAMPLEPRODUCT\Bin\simpleservice.exe");
Console.WriteLine(fvi.FileVersion);
Thomas Levesque
2009-09-07 08:26:20
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\Binis 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 differentfile
peter
2009-09-07 08:52:24
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
2009-09-07 09:21:08
+2
A:
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
2009-09-07 08:26:50
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
2009-09-07 08:30:38
here inside Assembly.LoadFrom("...") what we need to give physical path of exe or ?
peter
2009-09-07 08:33:09
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
2009-09-07 08:33:46
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
2009-09-07 08:44:01
+1
A:
AssemblyName anm = AssemblyName.GetAssemblyName(
"c:\\winnt\\microsoft.net\\framework\\v1.0.3705\\mscorlib.dll");
// and show its version
Console.WriteLine(anm.Version.ToString());
ArsenMkrt
2009-09-07 08:27:27
yea but he marks the question with winform and C# tag which give me an assumption that he mean .net assembly
ArsenMkrt
2009-09-07 09:17:36
+1
A:
AssemblyName.GetAssemblyName(@"F:\SAMPLEPRODUCT\Bin\simpleservice.exe").Version
Tadas
2009-09-07 08:28:05
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\Binis 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 differentfile
peter
2009-09-07 08:55:05
+1
A:
public string AssemblyVersion
{
get
{
return Assembly.GetExecutingAssembly().GetName().Version.ToString();
}
}
Mahin
2009-09-07 08:31:52