{"id":316,"date":"2009-11-06T18:13:19","date_gmt":"2009-11-06T17:13:19","guid":{"rendered":"http:\/\/www.lightsoft.se\/?p=316"},"modified":"2009-11-06T20:29:47","modified_gmt":"2009-11-06T19:29:47","slug":"c-check-update-from-application","status":"publish","type":"post","link":"https:\/\/www.lightsoftai.com\/?p=316","title":{"rendered":"C# Application that checks for new versions"},"content":{"rendered":"<p>Normally when I create some application and know that users will use it a lot, there is a underlying need of making sure the end user is using the latest version.<\/p>\n<p>To show one way of making this possible is using xml files at the server side, describing the changes and where to fetch new versions.<br \/>\nSo in other means, the code explain it self&#8230;.<\/p>\n<p><a href=\"http:\/\/www.lightsoft.se\/_lightsoft\/wp-content\/uploads\/2009\/11\/OrdinaryApp.zip\">OrdinaryApp.zip<\/a> Containing the source with example.<\/p>\n<p>[sourcecode language=&#8221;csharp&#8221;]<br \/>\npublic static string VERSION = &#8220;0.5&#8221;;<\/p>\n<p>public Form1()<br \/>\n{<br \/>\nInitializeComponent();<\/p>\n<p>\/\/ Register the Event to trigger a method when Updates are found.<br \/>\neventCatcher();<br \/>\n}<\/p>\n<p>private void eventCatcher()<br \/>\n{<\/p>\n<p>CheckUpdate.NewVersionToDownloadEvent += new CheckUpdate.NewVersionToDownload(newVersion);<br \/>\n}<\/p>\n<p>\/\/\/<br \/>\n\/\/\/ Get the new version available<br \/>\n\/\/\/<br \/>\n\/\/\/<br \/>\nprivate void newVersion(object newVersion)<br \/>\n{<br \/>\nNewVersion nV = (NewVersion)newVersion;<br \/>\nDialogResult dr =<br \/>\nMessageBox.Show(nV.MessageFromXml, &#8220;New version:&#8221; + nV.Version + &#8221; is available.&#8221;,<br \/>\nMessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1,<br \/>\nMessageBoxOptions.ServiceNotification);<br \/>\nif (dr == DialogResult.Yes)<br \/>\n{<br \/>\nProcess.Start(nV.Url + nV.Filename);<br \/>\n}<br \/>\n}<\/p>\n<p>\/\/\/<br \/>\n\/\/\/ The metod triggerd when the application has loaded.<br \/>\n\/\/\/<br \/>\n\/\/\/<br \/>\n\/\/\/<br \/>\nprivate void onLoad(object sender, EventArgs e)<br \/>\n{<br \/>\n\/\/ This could be when started, or button or other thing.<br \/>\nnew CheckUpdate(false, VERSION, &#8220;http:\/\/www.lightsoft.se\/_software_updates\/OrdinaryApp.xml&#8221;);<br \/>\n}<br \/>\n[\/sourcecode]<\/p>\n<p>Then the XML file describing the versions could look like this:<br \/>\n[sourcecode language=&#8221;xml&#8221;]<br \/>\n<!--<update currentversionnumber=\"0.7\" downloadurl=\"http:\/\/www.lightsoft.se\">--><br \/>\n<update currentversionnumber=\"1.0\" downloadurl=\"http:\/\/www.lightsoft.se\/_software_updates\/UpdateTestApp\/\" filename=\"OrdinaryApp.zip\"><br \/>\n  <version versionnumber=\"1.1\" versiondate=\"2008-09-01\"><br \/>\n    <newfeature>Added autocheck if an update is possible<\/newfeature><br \/>\n    <bugfix>Change the thread management for the text to be update. New rules in .Net 3.0<\/bugfix><br \/>\n  <\/version><br \/>\n  <version versionnumber=\"1.0\" versiondate=\"2008-08-01\">\n    <performance>Faster calculations<\/performance>\n  <\/version><br \/>\n  <version versionnumber=\"0.1\" versiondate=\"2004-01-01\"><br \/>\n    <newfeature>Main application done<\/newfeature><br \/>\n  <\/version><br \/>\n  <version versionnumber=\"0.0.1\" versiondate=\"2003-12-01\"><br \/>\n    <newfeature>Beta 1<\/newfeature><br \/>\n  <\/version><br \/>\n<\/update><\/p>\n<p>[\/sourcecode]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Normally when I create some application and know that users will use it a lot, there is a underlying need of making sure the end user is using the latest version. To show one way of making this possible is using xml files at the server side, describing the changes and where to fetch new [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[39,32,29],"class_list":["post-316","post","type-post","status-publish","format-standard","hentry","category-c-csharp","tag-c","tag-download","tag-projects"],"_links":{"self":[{"href":"https:\/\/www.lightsoftai.com\/index.php?rest_route=\/wp\/v2\/posts\/316","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.lightsoftai.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.lightsoftai.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.lightsoftai.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.lightsoftai.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=316"}],"version-history":[{"count":29,"href":"https:\/\/www.lightsoftai.com\/index.php?rest_route=\/wp\/v2\/posts\/316\/revisions"}],"predecessor-version":[{"id":355,"href":"https:\/\/www.lightsoftai.com\/index.php?rest_route=\/wp\/v2\/posts\/316\/revisions\/355"}],"wp:attachment":[{"href":"https:\/\/www.lightsoftai.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=316"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lightsoftai.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=316"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lightsoftai.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=316"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}