Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ProductName and CompanyName in C#

In VB.Net, I can retrieve my application's ProductName and CompanyName by using:

My.Application.Info.ProductName
My.Application.Info.CompanyName

How do I do the same thing in C#?

like image 321
Hand-E-Food Avatar asked Dec 01 '11 00:12

Hand-E-Food


3 Answers

You can use Assembly and FileVersionInfo

Assembly assembly = Assembly.GetExecutingAssembly();
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location);
var companyName = fvi.CompanyName;
var productName = fvi.ProductName;
var productVersion = fvi.ProductVersion;
like image 52
Peter PAD Avatar answered Nov 15 '22 06:11

Peter PAD


Just use:

System.Windows.Forms.Application.ProductName
System.Windows.Forms.Application.CompanyName

...in assembly System.Windows.Forms.dll

Or if you prefer:

using System.Windows.Forms;
//...
string productName = Application.ProductName;
string companyName = Application.CompanyName;
like image 22
rfmodulator Avatar answered Nov 15 '22 08:11

rfmodulator


You need to reference the Microsoft.VisualBasic.MyServices namespace. See this for more info. You can't use the exact same syntax though. There are also more general .net ways that you would normally use in c# to get the same kind of info you get from My.Whatever in VB but they are completely unrelated to each other. There is no direct equivalent of using My.Whatever in c# the language.

like image 2
Ben Robinson Avatar answered Nov 15 '22 06:11

Ben Robinson