ApplicationDeployment.CheckForUpdate Method

Note: This method is new in the .NET Framework version 2.0.

Checks UpdateLocation to determine whether a new update is available.

Namespace: System.Deployment.Application
Assembly: System.Deployment (in system.deployment.dll)

public bool CheckForUpdate ()
public boolean CheckForUpdate ()
public function CheckForUpdate () : boolean

Return Value

true if a new update is available; otherwise, false.

Exception typeCondition

InvalidOperationException

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 void InstallUpdateSyncWithInfo()
{
    UpdateCheckInfo info = null;

    if (ApplicationDeployment.IsNetworkDeployed)
    {
        ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment;

        try
        {
            info = ad.CheckForDetailedUpdate();

        }
        catch (DeploymentDownloadException dde)
        {
            MessageBox.Show("The new version of the application cannot be downloaded at this time. \n\nPlease check your network connection, or try again later. Error: " + dde.Message);
            return;
        }
        catch (InvalidDeploymentException ide)
        {
            MessageBox.Show("Cannot check for a new version of the application. The ClickOnce deployment is corrupt. Please redeploy the application and try again. Error: " + ide.Message);
            return;
        }
        catch (InvalidOperationException ioe)
        {
            MessageBox.Show("This application cannot be updated. It is likely not a ClickOnce application. Error: " + ioe.Message);
            return;
        }

        if (info.UpdateAvailable)
        {
            Boolean doUpdate = true;

            if (!info.IsUpdateRequired)
            {
                DialogResult dr = MessageBox.Show("An update is available. Would you like to update the application now?", "Update Available", MessageBoxButtons.OKCancel);
                if (!(DialogResult.OK == dr))
                {
                    doUpdate = false;
                }
            }

            if (doUpdate)
            {
                try
                {
                    ad.Update();
                    MessageBox.Show("The application has been upgraded, and will now restart.");
                    Application.Restart();
                }
                catch (DeploymentDownloadException dde)
                {
                    MessageBox.Show("Cannot install the latest version of the application. \n\nPlease check your network connection, or try again later. Error: " + dde);
                    return;
                }
            }
        }
    }
}

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.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show: