ProductName and CompanyName in C#

17,307

Solution 1

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;

Solution 2

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;

Solution 3

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.

Share:
17,307
Hand-E-Food
Author by

Hand-E-Food

Updated on June 23, 2022

Comments

  • Hand-E-Food
    Hand-E-Food almost 2 years

    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#?

  • Hand-E-Food
    Hand-E-Food over 12 years
    I always found it odd that C#, for all it's power, doesn't include the niceties found in the VisualBasic namespace.
  • Hand-E-Food
    Hand-E-Food over 12 years
    I like this. It doesn't require extra references.
  • Hand-E-Food
    Hand-E-Food over 12 years
    How have those properties escaped me all this time? Thanks!
  • rfmodulator
    rfmodulator over 12 years
    @Hand-E-Food - After I lost the answer I was afraid you would continue to remain oblivious. :)
  • rfmodulator
    rfmodulator over 12 years
    Agreed, this is the best way for a console application.
  • SteveCinq
    SteveCinq about 5 years
    Fine for a Windows form, no good for a class library. I didn't vote down but would have if (anon) down voting didn't annoy me so much with my own posts!