Creating Self-Updating Applications in .NET Compact Framework
Last Updated: Oct 30, 2025
5 min read
Legacy Archive
In any application software, there's always a need for updates or enhancements due to additional features that need to be incorporated into the existing system on an ongoing basis. The existing identified bugs also need to be addressed with upgrades in the running version.
To make software up-to-date and meet changing trends, you'll need to keep enhancing your application software at regular intervals. As someone not deeply involved in the application's evolution, you might not know when to update your app, how to fix recently reported bugs, or how to keep track of version control. This is where self-updating applications come in.
Understanding Self-Update Architecture
There are always two major parts in any self-updating application: the updater applet and the web service. These two components are responsible for directing users to where they can get information and know the exact location of available updates.
The minimum requirement is a web server that can provide the update facility for devices and carry out the update process based on various identified devices accessing the web server. Out of the various platforms available today for update servers, IIS and ASP.NET are very popular. ASP.NET is a superior tool used today for any web-based service.
XML-Based Update Configuration
It's possible to maintain a database of all available updates in an XML document format. XML-based files are easy to load, edit, and save, which is why XML documents are extensively used in any web-based services. The XML document will contain information about different update modules for various device configurations and architectures.
In any XML document, the root element contains the information on updates, and the child element can be a download module used by different platforms. The child element gives information on the compatible architecture, application name, version type, major version, minor version, build number, and other relevant details.
Client-Side Configuration
The applet incorporated into the updater application checks the mobile device, and once a suitable update is identified, information is sent to the mobile device prompting the user to choose from available options and download the required one. Depending on the user's response, the update will either be downloaded or the device will disconnect from the network.
The tags serve different purposes: checkassembly name retrieves version information, remoteapp name decides on the exact update required, and service provides the URL of the web service to use with this application.
Implementing the Update Logic
You'll be able to read and retrieve any details regarding the XML configuration by simply loading the XML document. The update service is implemented as a web service, with the URL set dynamically.
UpdateClient.cs
using System.Xml;
using System.Net;
// Load configuration document
XmlDocument config = new XmlDocument();
config.Load(configDocumentPath);
// Set up the web service URL dynamically
UpdateAgent agent = new UpdateAgent();
agent.Url = config["updateinfo"]["service"].GetAttribute("url");
// Get update information
string appName = config["updateinfo"]["remoteapp"].GetAttribute("name");
string currentVersion = GetCurrentVersion();
string cpuArchitecture = GetCPUArchitecture();
UpdateInfo updateInfo = agent.GetUpdateInfo(appName,
currentVersion,
cpuArchitecture);
if (updateInfo.UpdateAvailable)
{
// Download the CAB file
DownloadUpdate(updateInfo.DownloadUrl);
}
Download and Installation Process
The most commonly used method to invoke the update service is GetUpdateInfo. Once the call is routed and connection established successfully, you can assess the necessity for the update from available information. On establishing the connection, details about the CPU architecture will be passed to the web server, and the correct CAB file (Cabinet file) will be transferred to the device using the HttpWebRequest class.
DownloadManager.cs
private void DownloadUpdate(string downloadUrl)
{
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(downloadUrl);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string tempPath = Path.GetTempPath();
string cabFileName = Path.Combine(tempPath, "update.cab");
using (Stream responseStream = response.GetResponseStream())
using (FileStream fileStream = new FileStream(cabFileName,
FileMode.Create))
{
byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = responseStream.Read(buffer, 0,
buffer.Length)) > 0)
{
fileStream.Write(buffer, 0, bytesRead);
}
}
// Prompt user to install
if (MessageBox.Show("Update downloaded. Install now?",
"Update Available",
MessageBoxButtons.YesNo) == DialogResult.Yes)
{
InstallUpdate(cabFileName);
}
}
catch (Exception ex)
{
MessageBox.Show("Error downloading update: " + ex.Message);
}
}
Finally, on the availability of an appropriate update, the file will be downloaded to the device and the user will be prompted for installation. The self-updating mechanism ensures your mobile applications stay current without manual intervention.
FAQ
What are the two major components of a self-updating application?
The two major parts are the updater applet (embedded in the mobile app) and the web service (hosted on a server). These components work together to check for updates, determine device compatibility, and deliver the appropriate update files.
Why use XML format for storing update information?
XML files are easy to load, edit, and save, making them ideal for web-based services. They can store update information for different device configurations, architectures, and versions in a structured, readable format that both the server and client can easily process.
How does the update process handle different device architectures?
The XML configuration includes platform and architecture attributes for each update module. When a device checks for updates, it sends its CPU architecture details to the server, which then provides the correct CAB file matched to that specific device configuration.
What's the role of the GetUpdateInfo method?
GetUpdateInfo is the primary method to invoke the update service. Once the connection is established, it assesses whether updates are needed based on version information, device architecture, and available updates on the server.