Dev Direct Solution Center

For more information and to buy this product...

Use wodAppUpdate to automatically update an application over the Internet

  For a copy of the sample project please click here to download and install the product evaluation.

Introduction

This samples shows how the wodAutoUpdate ActiveX control provides everything you need to remotely maintain your app across the Internet - communicate with the server, compare file versions and download newer files, making it quick and simple to provide an auto-update facility from within your application.

Detail

Our demonstration code illustrates a simple case in which we make a call to our HTTP server (in this case we use "localhost"), request a file which contains the version number of the latest files and then perform a download and update if the file on the server is newer than the local file.

Set up

Download and run the executable from the above link. The samples will be placed in directory C:\Program Files\WeOnlyDo.Com\AppUpdate\Samples. There are example projects for C# and VB.

In the VB6 project, the control wodAppUpdate is placed on Form1 and event handlers are provided by the development environment.

The C# project references the wodAppUpdateCom component with a form-wide variable called wodAppUpdate1 . Handlers are added in Form1_Load for events that will be raised after each method is called.

This example handles CheckDone, which is raised after the version check is performed so that you can offer users the choice to upgrade and DownloadDone, which is raised after the download of new files is complete and can be used to control whether the upgrade is done now or later.

C#
private WODAPPUPDATECOMLib.wodAppUpdateCom wodAppUpdate1 private void Form1_Load(object sender, EventArgs e) { wodAppUpdate1 = new WODAPPUPDATECOMLib.wodAppUpdateCom(); wodAppUpdate1.CheckDone += new WODAPPUPDATECOMLib._IwodAppUpdateComEvents_CheckDoneEventHandler(wodAppUpdate1_CheckDone); wodAppUpdate1.CloseApp += new WODAPPUPDATECOMLib._IwodAppUpdateComEvents_CloseAppEventHandler(wodAppUpdate1_CloseApp); wodAppUpdate1.DownloadDone += new WODAPPUPDATECOMLib._IwodAppUpdateComEvents_DownloadDoneEventHandler(wodAppUpdate1_DownloadDone); wodAppUpdate1.PrevDetected += new WODAPPUPDATECOMLib._IwodAppUpdateComEvents_PrevDetectedEventHandler(wodAppUpdate1_PrevDetected); }

Checking for Updates

The check is initiated when the button is pressed. The code calls the Check method, passing the location on the server of the file containing version information.

VB6
wodAppUpdate1.Check "http://www.weonlydo.com/AppUpdate/test/update.php"
C#
wodAppUpdate1.Check("http://www.weonlydo.com/AppUpdate/test/update.php", false);

Calling the Check method will cause the CheckDone event to be fired and the parameter NewFiles will be true if there are any newer versions of any of the files listed in myApp.upd. We can use this event to download the files across the network from the server using the Download method.

VB6
Private Sub wodAppUpdate1_CheckDone(ByVal NewFiles As Long, ByVal ErrorCode As Long, ByVal ErrorText As String) ' fired when wodappupdate finishes checking for new files ' based on your online script If ErrorCode = 0 Then If NewFiles Then If MsgBox("New files found. Download?", vbYesNo + vbQuestion, "New files found!") = vbYes Then wodAppUpdate1.Download End If Else MsgBox "No new versions found. Your application is up-to-date.", vbOKOnly + vbExclamation End If End If End Sub
C#
void wodAppUpdate1_CheckDone(int NewFiles, int ErrorCode, string ErrorText) { // fired when wodappupdate finishes checking for new files // based on your online script if (ErrorCode == 0) { if (NewFiles>0) { System.Windows.Forms.DialogResult msgres = System.Windows.Forms.MessageBox.Show("New files found. Download?", "New files found", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (msgres == DialogResult.Yes) { wodAppUpdate1.Download(); } } else { System.Windows.Forms.MessageBox.Show("No new versions found. Your application is up-to-date.", "No new files"); } }

Updating the Files

Following the download, the DownloadDone event will fire and you can use the Update method to replace your files with the downloaded versions.

VB6
Private Sub wodAppUpdate1_DownloadDone(ByVal ErrorCode As Long, ByVal ErrorText As String) ' fired when wodappupdate downloads all necessary files If ErrorCode = 0 Then If MsgBox("Download successful. Replace now?", vbYesNo + vbQuestion, "Replace files..") = vbYes Then wodAppUpdate1.Update End If Else MsgBox "There was an error downloading: " & ErrorText End If End Sub

If your app needs to be closed to complete the update the CloseApp event is then fired.

Summary

This simple demonstration shows how wodAutoUpdate can easily deliver HTTP communications, version checking, file download and update functionality out of the box in just a few method calls.

Visit WeOnlyDo! Inc. for more information and more samples.