Created
April 25, 2023 16:19
-
-
Save nilesh93/096efc20f727ea63dbd81b1b1e690076 to your computer and use it in GitHub Desktop.
.net update
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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