Click here to Skip to main content
15,889,858 members
Articles / Programming Languages / C#
Tip/Trick

Adding Version Info to your Winforms app in 3 (4) Easy Steps

Rate me:
Please Sign up or sign in to vote.
4.44/5 (14 votes)
18 Feb 2016CPOL 9.2K   15  
Easily add Version Information to the main form Title bar of your Winforms app

Like a Version

  1. In AssemblyInfo.cs, change this:
    C#
    [assembly: AssemblyVersion("1.0.0.0")]

    ...to this:

    C#
    [assembly: AssemblyVersion("1.0.*")]
  2. Add "using System.Reflection;" to your main form.
  3. Add this method to your main form:
    C#
    private void SetVersionInfo()
    {
        Version versionInfo = Assembly.GetExecutingAssembly().GetName().Version;
        DateTime startDate = new DateTime(2000, 1, 1);
        int diffDays = versionInfo.Build;
        DateTime computedDate = startDate.AddDays(diffDays);
        string lastBuilt = computedDate.ToShortDateString();
        this.Text = string.Format("{0} - Version {1} ({2})", 
                    this.Text, versionInfo.ToString(), lastBuilt);
    }
  4. Finally, in the main form's Load event, add a call to that method:
    C#
    private void FormMain_Load(object sender, EventArgs e)
    {
         SetVersionInfo();
    	 . . .
    }

Now when you run your app, it will append the version info to whatever your form's Text property is set to. This helps to verify that users are using the most recent (or most recently released, anyway) version of your app when they call for support. Of course, they never do that, so this tip is completely worthless.

License

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


Written By
Founder Across Time & Space
United States United States
I am in the process of morphing from a software developer into a portrayer of Mark Twain. My monologue (or one-man play, entitled "The Adventures of Mark Twain: As Told By Himself" and set in 1896) features Twain giving an overview of his life up till then. The performance includes the relating of interesting experiences and humorous anecdotes from Twain's boyhood and youth, his time as a riverboat pilot, his wild and woolly adventures in the Territory of Nevada and California, and experiences as a writer and world traveler, including recollections of meetings with many of the famous and powerful of the 19th century - royalty, business magnates, fellow authors, as well as intimate glimpses into his home life (his parents, siblings, wife, and children).

Peripatetic and picaresque, I have lived in eight states; specifically, besides my native California (where I was born and where I now again reside) in chronological order: New York, Montana, Alaska, Oklahoma, Wisconsin, Idaho, and Missouri.

I am also a writer of both fiction (for which I use a nom de plume, "Blackbird Crow Raven", as a nod to my Native American heritage - I am "½ Cowboy, ½ Indian") and nonfiction, including a two-volume social and cultural history of the U.S. which covers important events from 1620-2006: http://www.lulu.com/spotlight/blackbirdcraven

Comments and Discussions

 
-- There are no messages in this forum --