Usually, while designing a desktop application, we need a "AboutDialog" to show the product information, such as "Product Name", "Version" etc. Here are the code about it:
1. Get Assembly Title


1 private string AssemblyTitle
2 {
3 get
4 {
5 object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
6 if (attributes.Length > 0)
7 {
8 AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0];
9 if (titleAttribute.Title != "")
10 {
11 return titleAttribute.Title;
12 }
13 }
14 return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
15 }
16 }
2 {
3 get
4 {
5 object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
6 if (attributes.Length > 0)
7 {
8 AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0];
9 if (titleAttribute.Title != "")
10 {
11 return titleAttribute.Title;
12 }
13 }
14 return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
15 }
16 }
2. Get Assembly Version


private static string GetProductVersion()
{
string version = String.Empty;
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false);
if (attributes.Length == 0)
{
//just in case fall back to the regular dll version which is always there.
version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
}
else
{
version = ((AssemblyInformationalVersionAttribute)attributes[0]).InformationalVersion;
}
return version;
}
{
string version = String.Empty;
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false);
if (attributes.Length == 0)
{
//just in case fall back to the regular dll version which is always there.
version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
}
else
{
version = ((AssemblyInformationalVersionAttribute)attributes[0]).InformationalVersion;
}
return version;
}
3. Get Development Company


private string AssemblyCompany
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
if (attributes.Length == 0)
{
return "";
}
return ((AssemblyCompanyAttribute)attributes[0]).Company;
}
}
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
if (attributes.Length == 0)
{
return "";
}
return ((AssemblyCompanyAttribute)attributes[0]).Company;
}
}
4. Get Product Information


private string AssemblyProduct
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false);
if (attributes.Length == 0)
{
return "";
}
return ((AssemblyProductAttribute)attributes[0]).Product;
}
}
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false);
if (attributes.Length == 0)
{
return "";
}
return ((AssemblyProductAttribute)attributes[0]).Product;
}
}