Click here to Skip to main content
15,892,059 members
Articles / All Topics

Auto Updating Version Text

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
11 Jan 2010CPOL 6.6K   2  
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)


Written By
Software Developer
United States United States
I attended Southern Polytechnic State University and earned a Bachelors of Science in Computer Science and later returned to earn a Masters of Science in Software Engineering. I've largely developed solutions that are based on a mix of Microsoft technologies with open source technologies mixed in. I've got an interest in astronomy and you'll see that interest overflow into some of my code project articles from time to time.



Twitter:@j2inet

Instagram: j2inet


Comments and Discussions

 
-- There are no messages in this forum --