I want to determine the file version of dll file in 'c#' when the path is specified. Suppose path = "\x\y\z.dll" .
How to find the file version of z.dll when path is given?
NOTE: I use Compact Framework 3.5 SP1
Normal Framework
If it is a .NET DLL you can use Reflection.
using System.Reflection;
Assembly assembly = Assembly.LoadFrom("\x\y\z.dll");
Version ver = assembly.GetName().Version;
If not, you can use System.Diagnostics:
using System.Diagnostics;
static string GetDllVersion(string dllPath)
{
FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(dllPath);
return myFileVersionInfo.FileVersion;
}
// Sample invokation
string result = GetDllVersion(@"C:\Program Files (x86)\Google\Chrome\Application\20.0.1132.57\chrome.dll");
// result value **20.0.1132.57**
Compact Framework
If you are using .NET Compact Framework you don't have access to FileVersionInfo
You can check this stackoverflow question. In the unique answer you have a link to a blog with code that fixes your problem.