Click here to Skip to main content
Click here to Skip to main content

Automatically display your application version

, 23 Aug 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
Automatically display your application version in the UI

Introduction 

I often find myself creating quick utility applications. Because I don't spend a lot of time in the UI it can be difficult down the road to determine what version of the Utility Application someone is using. To help make this a little easier, I have adopted a method of "Stamping" the application version right on the main UI.  Of course you could set this text statically each time you increment your build, but with just a bit of code this can be updated for you automatically.

Sample of Version Label


Creating the Version label

In this section, I will demonstrate how to create the Version label within a C# application.

  • To create this label, simply add a Label to your Windows Form where you would like the version to be displayed.
  • Name the label lblVersion. 
  • Set the Text of the Label to- Version: {0}.{1}.{2}.{3}
 Label added in Vsiual Studio
  • Double click on the form to create the event for the Form_Load method.
  • Note, you will likely need to add the System.Reflection into your using statements section:
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
 
namespace Sample_Version_App
{ 
  • In the event, include the following code:
private void Form1_Load(object sender, EventArgs e)
{
	//set version info
	Version version = Assembly.GetExecutingAssembly().GetName().Version;            
	this.lblVersion.Text = String.Format(this.lblVersion.Text, version.Major, version.Minor, version.Build, version.Revision);
}
  • In this code we get the Version object for the executing application. Using this object we then set the text of the label to show the Major.Minor.Build.Revision of the application.
  • Run the application, note that the version set from the Applications Assembly information is displayed in the form.
Results of the sample application - Shows the app version

Points of Interest

In this project I added the code to dynamically set the version information directly into my main application, but the same concepts could be used to create a User Control that provides the same functionality.


History

  • 08/23/2012
    • Initial publishing of Tip/Trick

License

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

Share

About the Author

Chip VonBurg
Software Developer (Senior)
United States United States
No Biography provided

Comments and Discussions

 
SuggestionFor people using ClickOnce... PinmemberAndrewB-UK24-Aug-12 3:46 
GeneralMy vote of 4 Pinmemberfurill24-Aug-12 3:07 
QuestionChanging Version Number PingroupPurushotham Agaraharam24-Aug-12 2:09 
AnswerRe: Changing Version Number Pinmembertipsybroom24-Aug-12 3:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141220.1 | Last Updated 23 Aug 2012
Article Copyright 2012 by Chip VonBurg
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid