ApplicationDeployment.CheckForUpdate Method
Assembly: System.Deployment (in system.deployment.dll)
'Declaration Public Function CheckForUpdate As Boolean 'Usage Dim instance As ApplicationDeployment Dim returnValue As Boolean returnValue = instance.CheckForUpdate
public boolean CheckForUpdate ()
public function CheckForUpdate () : boolean
Return Value
true if a new update is available; otherwise, false.| Exception type | Condition |
|---|---|
| ClickOnce will throw this exception immediately if you call this method while an update is already in progress. | |
DeploymentDownloadException | The deployment manifest cannot be downloaded. This exception will appear in the Error property of the CheckForUpdateCompleted event. |
InvalidDeploymentException | The deployment manifest is corrupted. You will likely need to redeploy the application to fix this problem. This exception will appear in the Error property of the CheckForUpdateCompleted event. |
The CheckForUpdate compares the version of the currently installed deployment with the version specified in the deployment manifest found at UpdateLocation. If the version on the server is greater than the installed version, it returns true.
This method will block until the check has completed. To check for an update asynchronously, use the CheckForUpdateAsync method instead.
The following code example checks for an application update; if one is available, it installs it synchronously.
Private Sub InstallUpdateSyncWithInfo() Dim info As UpdateCheckInfo = Nothing If (ApplicationDeployment.IsNetworkDeployed) Then Dim AD As ApplicationDeployment = ApplicationDeployment.CurrentDeployment Try info = AD.CheckForDetailedUpdate() Catch dde As DeploymentDownloadException MessageBox.Show("The new version of the application cannot be downloaded at this time. " + ControlChars.Lf + ControlChars.Lf + "Please check your network connection, or try again later. Error: " + dde.Message) Return Catch ioe As InvalidOperationException MessageBox.Show("This application cannot be updated. It is likely not a ClickOnce application. Error: " + ioe.Message) Return End Try If (info.UpdateAvailable) Then Dim doUpdate As Boolean = True If (Not info.IsUpdateRequired) Then Dim dr As DialogResult = MessageBox.Show("An update is available. Would you like to update the application now?", "Update Available", MessageBoxButtons.OKCancel) If (Not System.Windows.Forms.DialogResult.OK = dr) Then doUpdate = False End If End If If (doUpdate) Then Try AD.Update() MessageBox.Show("The application has been upgraded, and will now restart.") Application.Restart() Catch dde As DeploymentDownloadException MessageBox.Show("Cannot install the latest version of the application. " + ControlChars.Lf + ControlChars.Lf + "Please check your network connection, or try again later.") Return End Try End If End If End If End Sub
- PermissionSet For full access to the local computer. Associated enumeration: PermissionState
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.
Reference
ApplicationDeployment ClassApplicationDeployment Members
System.Deployment.Application Namespace
CheckForUpdateAsync