Share via

DownloadOperation Class


Performs an asynchronous download operation. The Background transfer sample demonstrates this functionality. For an overview of Background Transfer capabilities, see Transferring data in the background.

public ref class DownloadOperation sealed : IBackgroundTransferOperationPriority
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class DownloadOperation final : IBackgroundTransferOperationPriority
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
public sealed class DownloadOperation : IBackgroundTransferOperationPriority
Public NotInheritable Class DownloadOperation
Implements IBackgroundTransferOperationPriority
Object Platform::Object IInspectable DownloadOperation

Windows requirements

Device family
Windows 10 (introduced in 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v1.0)
App capabilities
internetClient internetClientServer privateNetworkClientServer


Sample applications that use this class include the Background transfer sample.

The following example demonstrates how to configure and begin a basic download operation.

using Windows.Foundation;
using Windows.Networking.BackgroundTransfer;
using Windows.Storage;

private async void StartDownload_Click(object sender, RoutedEventArgs e)
        Uri source = new Uri(serverAddressField.Text.Trim());
        string destination = fileNameField.Text.Trim();

        StorageFile destinationFile = await KnownFolders.PicturesLibrary.CreateFileAsync(
            destination, CreationCollisionOption.GenerateUniqueName);

        BackgroundDownloader downloader = new BackgroundDownloader();
        DownloadOperation download = downloader.CreateDownload(source, destinationFile);

        // Attach progress and completion handlers.
        HandleDownloadAsync(download, true);
    catch (Exception ex)
        LogException("Download Error", ex);


At next start-up after application termination, your application should enumerate all existing DownloadOperation instances using GetCurrentDownloadsAsync. When a UWP application using Background Transfer is terminated, incomplete downloads persist in the background. If your application is restarted after termination and these incomplete operations are not enumerated and re-introduced to the current session, then they will go stale and continue to occupy device resources.

Background transfer doesn't support concurrent downloads of the same Uri. So an app can download once, or download it again after a previous download completed. An app shouldn't start two downloads of the same Uri concurrently, since this may result in truncated files.


Paused or incomplete download operations can only be resumed if the server accepts range-requests.

Timeout considerations

  1. When establishing a new connection for a download over TCP/SSL, the connection attempt is aborted if not established within five minutes.
  2. After the connection has been established, an HTTP request message that has not received a response within two minutes is aborted. Assuming there is Internet connectivity, Background Transfer will retry a download up to three times. In the event Internet connectivity is not detected, additional attempts will not be made until it is.

Debugging Guidance

Stopping a debugging session in Microsoft Visual Studio is comparable to closing your app; downloads are paused and POST uploads are terminated. Even while debugging, your app should enumerate and then pause, resume, restart, or cancel any persisted downloads.

However, if Microsoft Visual Studio project updates, like changes to the app manifest, require that the app is uninstalled and re-deployed for debugging, GetCurrentDownloadsAsync cannot enumerate persisted operations created using the previous app deployment.

Version history

Windows version SDK version Value added
1709 16299 CurrentWebErrorStatus
1709 16299 GetDownloadedRanges
1709 16299 GetResultRandomAccessStreamReference
1709 16299 IsRandomAccessRequired
1709 16299 RangesDownloaded
1709 16299 RecoverableWebErrorStatuses
1803 17134 MakeCurrentInTransferGroup
2004 19041 RemoveRequestHeader
2004 19041 SetRequestHeader



Gets and sets the cost policy for the download.


A transfer's WebErrorStatus, which can be monitored during the lifetime of the DownloadOperation.



Group may be altered or unavailable for releases after Windows 8.1. Instead, use TransferGroup.

Gets a string value indicating the group the transfer belongs to.


This is a unique identifier for a specific download operation. A GUID associated to a download operation will not change for the duration of the download.


A boolean property to enable random access. The property must be set to TRUE before calling StartAsync() on a DownloadOperation object to use the random access feature. After calling StartAsync(), call GetResultRandomAccessStreamReference to get a reference to the random access stream and read from it.


Gets the method to use for the download.


Gets or sets the transfer priority of this download operation when within a BackgroundTransferGroup. Possible values are defined by BackgroundTransferPriority.


Gets the current progress of the operation.


A set of WebErrorStatus values that applications anticipate the download will hit, and that the applications know how to handle.


Gets the URI from which to download the file.


Returns the IStorageFile object provided by the caller when creating the DownloadOperation object using CreateDownload.


Gets the group that this download operation belongs to.



Returns an asynchronous operation that can be used to monitor progress and completion of the attached download. Calling this method allows an app to attach download operations that were started in a previous app instance.


Returns the full list of file ranges that have been downloaded so far.


Gets the response information.


Gets a reference to the random access stream and reads from it. It's necessary to set IsRandomAccessRequired to TRUE before calling GetResultRandomAccessStreamReference.


Gets the partially downloaded response at the specified position.


Prioritizes the download transfer operation (and any transfers that follow it in the same transfer group). Calling this method on a transfer that doesn't belong to a transfer group has no effect.


Pauses a download operation.


Used to remove an HTTP request header.


Resumes a paused download operation.

SetRequestHeader(String, String)

Used to set an HTTP request header.


Starts an asynchronous download operation.



Provides access to incremental download progress.

Applies to

See also