DeploymentProgressChangedEventArgs.BytesCompleted Property

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets the number of bytes already downloaded by this operation.

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

public long BytesCompleted { get; }

Property Value

Type: System.Int64

An Int64 representing the data already transferred, in bytes.

For CheckForUpdateProgressChanged, the BytesCompleted property refers to the downloading of the deployment manifest. For UpdateProgressChanged, the property refers to the download progress of the entire update, included the manifests, assemblies, and data files. For DownloadFileGroupProgressChanged, the property refers to the download progress of the entire set of files that are part of the named group.

The following code example downloads a file group named HelpFiles, and displays download progress in a status bar. This example requires that you deploy a Windows Forms application, and that your main form has a StatusStrip control, and a ToolStripStatusLabel control named downloadStatus.

private void DownloadFileGroupAsync(string fileGroup)
{
    if (ApplicationDeployment.IsNetworkDeployed)
    {
        ApplicationDeployment deployment = ApplicationDeployment.CurrentDeployment;

        try
        {
            if (!deployment.IsFileGroupDownloaded(fileGroup))
            {
                deployment.DownloadFileGroupProgressChanged += new DeploymentProgressChangedEventHandler(deployment_DownloadFileGroupProgressChanged);
                deployment.DownloadFileGroupCompleted += new DownloadFileGroupCompletedEventHandler(deployment_DownloadFileGroupCompleted);

                deployment.DownloadFileGroupAsync(fileGroup);
            }
        }
        catch (InvalidOperationException ioe)
        {
            MessageBox.Show("This application is not a ClickOnce application. Error: " + ioe.Message);
            return;
        }
    }
}

void deployment_DownloadFileGroupProgressChanged(object sender, DeploymentProgressChangedEventArgs e)
{
    downloadStatus.Text = String.Format("Downloading file group {0}; {1:D}K of {2:D}K completed.", e.Group, e.BytesCompleted / 1024, e.BytesTotal / 1024);               
}

void deployment_DownloadFileGroupCompleted(object sender, DownloadFileGroupCompletedEventArgs e)
{
    if (e.Error != null)
    {
        downloadStatus.Text = "Could not download files. Will try again later.";
        return;
    }
    else if (e.Cancelled)
    {
        downloadStatus.Text = "The file download has been cancelled.";
        return;
    }

    downloadStatus.Text = String.Format("Download of file group {0} complete.", e.Group);
}

.NET Framework
Available since 2.0
Return to top
Show: