I have two assemblies A.exe and B.exe. Both are Windows.Forms .net 3.5 assemblies. A.exe knows that B.exe is in the same directory.
How can I find out the ProductName of B.exe from A.exe?
I have two assemblies A.exe and B.exe. Both are Windows.Forms .net 3.5 assemblies. A.exe knows that B.exe is in the same directory.
How can I find out the ProductName of B.exe from A.exe?
The following is an example on how to read assembly information through code.
http://www.c-sharpcorner.com/UploadFile/ravesoft/Page112282007015536AM/Page1.aspx
And you can load a specific assembly using [Assembly.Load()][1]
method.
This method might help you.
You need the name space "System.Reflection" to use the code below.
//fileName = @"...\B.exe"; //The full path of the file you want to load
public string GetAssemblyProductName(string fileName)
{
Assembly fileAssembly = null;
try
{
fileAssembly = Assembly.LoadFile(fileName);//Loading Assembly from a file
}
catch (Exception error)
{
Console.WriteLine("Error: {0}", error.Message);
return string.Empty;
}
if (fileAssembly != null)
{
string productName = fileAssembly.GetName().Name;//This is for getting Product Name
//string productName = fileAssembly.GetName().FullName;//This is for getting Full Name
return productName;
}
else
{
Console.WriteLine("Error: Not valid assembly.");
return string.Empty;
}
}
The FileVersionInfo class is useful here. The [AssemblyProduct] attribute gets compiled into the unmanaged version info resource. This code works on any .exe:
private void button1_Click(object sender, EventArgs e) {
var info = System.Diagnostics.FileVersionInfo.GetVersionInfo(@"c:\windows\notepad.exe");
MessageBox.Show(info.ProductName);
}