Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / All-Topics

Auto Updating Version Text

0.00/5 (No votes)
11 Jan 2010CPOL 6.7K  
I was making an application with an About dialog that shows the version number for the app. Rather than add the version number as static text, I made use of reflection to extract the version number from the assembly.

I was making an application with an About dialog that shows the version number for the app. Rather than add the version number as static text, I made use of reflection to extract the version number from the assembly. If you are interested in doing the same in your application, you can use the following code to get the version number text.

C#
Regex versionRegex = new Regex("Version=(?\\d\\.\\d\\.\\d\\.\\d)");

String GetVersion()
{
    string fullName = (this.GetType().Assembly.FullName).ToString();
    Match m = versionRegex.Match(fullName);
    if(m.Success)
    {
        return String.Format("{0}", m.Groups["ver"].Value);
    }
    else
    {
        return "";
    }
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)