Skip to content

Instantly share code, notes, and snippets.

@nilesh93
Created April 25, 2023 16:19
Show Gist options
  • Save nilesh93/096efc20f727ea63dbd81b1b1e690076 to your computer and use it in GitHub Desktop.
Save nilesh93/096efc20f727ea63dbd81b1b1e690076 to your computer and use it in GitHub Desktop.
.net update
// Define the URL where updates are available
string updateUrl = "http://yourdomain.com/update.xml";
// Check for updates
var updateChecker = new System.Net.WebClient();
string updateXml = updateChecker.DownloadString(updateUrl);
// Parse the update XML
var doc = new System.Xml.XmlDocument();
doc.LoadXml(updateXml);
string latestVersion = doc.SelectSingleNode("/Update/LatestVersion").InnerText;
string updateUrl = doc.SelectSingleNode("/Update/DownloadUrl").InnerText;
// Compare the latest version with the current version
if (latestVersion != Application.ProductVersion)
{
// Download and install the update
var downloader = new System.Net.WebClient();
downloader.DownloadFile(updateUrl, "update.exe");
var psi = new System.Diagnostics.ProcessStartInfo();
psi.FileName = "update.exe";
psi.Arguments = "/SILENT"; // Run the installer silently
System.Diagnostics.Process.Start(psi);
// Exit the application so the installer can run
Application.Exit();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment