UploadOperation UploadOperation UploadOperation UploadOperation UploadOperation Class


Some information relates to pre-released product which may be substantially modified before it’s commercially released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Prerelease APIs are identified by a Prerelease label.

[Contains prerelease APIs.]
Performs an asynchronous upload operation. For an overview of Background Transfer capabilities, see Transferring data in the background. Download the Background Transfer sample for examples in JavaScript, C#, and C++.

public : sealed class UploadOperation : IBackgroundTransferOperation, IBackgroundTransferOperationPriority, IUploadOperation, IUploadOperation2
struct winrt::Windows::Networking::BackgroundTransfer::UploadOperation : IBackgroundTransferOperation, IBackgroundTransferOperationPriority, IUploadOperation, IUploadOperation2
public sealed class UploadOperation : IBackgroundTransferOperation, IBackgroundTransferOperationPriority, IUploadOperation, IUploadOperation2
Public NotInheritable Class UploadOperation Implements IBackgroundTransferOperation, IBackgroundTransferOperationPriority, IUploadOperation, IUploadOperation2
// This class does not provide a public constructor.
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
internetClientServer privateNetworkClientServer internetClient


The following example demonstrates how to configure and begin a basic upload operation, and is based on the Background Transfer sample offered in the Windows Sample Gallery.

        var upload = null;
        var promise = null;

        function UploadFile (uriString, file) {
            try {

                var uri = Windows.Foundation.Uri(uriString);
                var uploader = new Windows.Networking.BackgroundTransfer.BackgroundUploader();

                // Set a header, so the server can save the file (this is specific to the sample server).
                uploader.setRequestHeader("Filename", file.name);

                // Create a new upload operation.
                upload = uploader.createUpload(uri, file);

                // Start the upload and persist the promise to be able to cancel the upload.
                promise = upload.startAsync().then(complete, error, progress);
            } catch (err) {

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

        private async void StartUpload_Click(object sender, RoutedEventArgs e)
                Uri uri = new Uri(serverAddressField.Text.Trim());
                FileOpenPicker picker = new FileOpenPicker();
                StorageFile file = await picker.PickSingleFileAsync();

                BackgroundUploader uploader = new BackgroundUploader();
                uploader.SetRequestHeader("Filename", file.Name);

                UploadOperation upload = uploader.CreateUpload(uri, file);

                // Attach progress and completion handlers.
                HandleUploadAsync(upload, true);
            catch (Exception ex)
                LogException("Upload Error", ex);


After app termination, an app should enumerate all existing UploadOperation instances at next start-up using GetCurrentUploadsAsync. When a UWP app using Background Transfer is terminated, incomplete uploads will persist in the background. If the app is restarted after termination and these incomplete operations are not enumerated and re-introduced to the current session, they will go stale and continue to occupy device resources.Timeout considerations

  • 1.) When establishing a new connection for an upload 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 an upload 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; PUT uploads are paused and POST uploads are aborted. Even while debugging, your app should enumerate and then pause, restart, or cancel any persisted uploads.

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


CostPolicy CostPolicy CostPolicy CostPolicy CostPolicy

Gets and sets the cost policy for the upload.

public : BackgroundTransferCostPolicy CostPolicy { get; set; }
BackgroundTransferCostPolicy CostPolicy(); void CostPolicy(BackgroundTransferCostPolicy costpolicy);
public BackgroundTransferCostPolicy CostPolicy { get; set; }
Public ReadWrite Property CostPolicy As BackgroundTransferCostPolicy
var backgroundTransferCostPolicy = uploadOperation.costPolicy;
uploadOperation.costPolicy = backgroundTransferCostPolicy;
BackgroundTransferCostPolicy BackgroundTransferCostPolicy BackgroundTransferCostPolicy

Specifies whether the transfer can happen over costed networks.

Group Group Group Group Group


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

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

public : Platform::String Group { get; }
winrt::hstring Group();
public string Group { get; }
Public ReadOnly Property Group As string
var string = uploadOperation.group;
string string string

The group name.

Guid Guid Guid Guid Guid

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

public : Platform::Guid Guid { get; }
Guid Guid();
public Guid Guid { get; }
Public ReadOnly Property Guid As Guid
var guid = uploadOperation.guid;
Guid Guid Guid

The unique ID for this upload operation.

Method Method Method Method Method

Gets the method to use for the upload.

public : Platform::String Method { get; }
winrt::hstring Method();
public string Method { get; }
Public ReadOnly Property Method As string
var string = uploadOperation.method;
string string string

The method to use for the upload. This value can be GET, PUT, POST, RETR, STOR, or any custom value supported by the server.

Priority Priority Priority Priority Priority

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

public : BackgroundTransferPriority Priority { get; set; }
BackgroundTransferPriority Priority(); void Priority(BackgroundTransferPriority priority);
public BackgroundTransferPriority Priority { get; set; }
Public ReadWrite Property Priority As BackgroundTransferPriority
var backgroundTransferPriority = uploadOperation.priority;
uploadOperation.priority = backgroundTransferPriority;
See Also

Progress Progress Progress Progress Progress

Gets the current progress of the upload operation.

public : BackgroundUploadProgress Progress { get; }
BackgroundUploadProgress Progress();
public BackgroundUploadProgress Progress { get; }
Public ReadOnly Property Progress As BackgroundUploadProgress
var backgroundUploadProgress = uploadOperation.progress;
BackgroundUploadProgress BackgroundUploadProgress BackgroundUploadProgress

The delegate to invoke when progress is available for a transfer operation.


The value of the Progress property is updated in real time, which means that the value can change while a progress handler is executing. As a best practice, create a local copy of the Progress property at the beginning of your progress handler, and use only that copy in your progress handler, to maintain a consistent view of progress as your handler executes.

RequestedUri RequestedUri RequestedUri RequestedUri RequestedUri

Gets the URI to upload from.

public : Uri RequestedUri { get; }
Uri RequestedUri();
public Uri RequestedUri { get; }
Public ReadOnly Property RequestedUri As Uri
var uri = uploadOperation.requestedUri;
Uri Uri Uri

The URI to upload from.

SourceFile SourceFile SourceFile SourceFile SourceFile

Specifies the IStorageFile to upload.

public : IStorageFile SourceFile { get; }
IStorageFile SourceFile();
public IStorageFile SourceFile { get; }
Public ReadOnly Property SourceFile As IStorageFile
var iStorageFile = uploadOperation.sourceFile;
IStorageFile IStorageFile IStorageFile

The file item to upload.

TransferGroup TransferGroup TransferGroup TransferGroup TransferGroup

Gets the group that this upload operation belongs to.

public : BackgroundTransferGroup TransferGroup { get; }
BackgroundTransferGroup TransferGroup();
public BackgroundTransferGroup TransferGroup { get; }
Public ReadOnly Property TransferGroup As BackgroundTransferGroup
var backgroundTransferGroup = uploadOperation.transferGroup;
See Also


AttachAsync() AttachAsync() AttachAsync() AttachAsync() AttachAsync()

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

public : IAsyncOperationWithProgress<UploadOperation, UploadOperation> AttachAsync()
IAsyncOperationWithProgress<UploadOperation, UploadOperation> AttachAsync() const;
public IAsyncOperationWithProgress<UploadOperation, UploadOperation> AttachAsync()
Public Function AttachAsync() As IAsyncOperationWithProgress( Of UploadOperation )( Of UploadOperation )
Windows.Networking.BackgroundTransfer.UploadOperation.attachAsync().done( /* Your success and error handlers */ );


        function AttachUpload (loadedUpload) {
            try {
                upload = loadedUpload;
                promise = upload.attachAsync().then(complete, error, progress);
            } catch (err) {


While this method can be called from multiple app instances, developers should not attach callbacks from the primary app instance in a background task. This will cause BackgroundTransferHost.exe to hang.

GetResponseInformation() GetResponseInformation() GetResponseInformation() GetResponseInformation() GetResponseInformation()

Gets the response information.

public : ResponseInformation GetResponseInformation()
ResponseInformation GetResponseInformation() const;
public ResponseInformation GetResponseInformation()
Public Function GetResponseInformation() As ResponseInformation
var responseInformation = uploadOperation.getResponseInformation();

Contains the data returned by a server response.


This method returns an object that contains information about the current server response. When calling this method multiple times, the object returned will be the same as long as there is no new server response information available. Sometimes however, one upload consists of multiple requests to a server. If a request gets aborted due to some non-fatal error (e.g. machine lost internet connectivity, cost policy required upload to pause, application called Pause(), etc.), Background Transfer will invoke a new request and try to restart the upload. The response information from the server for this second request may be different than the one returned by the first request.

Returns null if any of the following conditions is true.

  • The transfer associated with the UploadOperation is being made using a protocol other than HTTP (e.g., FTP).
  • The UploadOperation hasn't yet begun.
  • There was a failure before any response from the server was received (e.g., connection couldn't be established).

GetResultStreamAt(UInt64) GetResultStreamAt(UInt64) GetResultStreamAt(UInt64) GetResultStreamAt(UInt64) GetResultStreamAt(UInt64)

Gets the partially uploaded response at the specified location.

public : IInputStream GetResultStreamAt(unsigned __int64 position)
IInputStream GetResultStreamAt(UInt64 position) const;
public IInputStream GetResultStreamAt(UInt64 position)
Public Function GetResultStreamAt(position As UInt64) As IInputStream
var iInputStream = uploadOperation.getResultStreamAt(position);
UInt64 UInt64 UInt64

The position at which to start reading.


MakeCurrentInTransferGroup() MakeCurrentInTransferGroup() MakeCurrentInTransferGroup() MakeCurrentInTransferGroup() MakeCurrentInTransferGroup()

Prerelease. Prioritizes the upload 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.

public : void MakeCurrentInTransferGroup()
void MakeCurrentInTransferGroup() const;
public void MakeCurrentInTransferGroup()
Public Function MakeCurrentInTransferGroup() As void
Additional features and requirements
Device family
Windows 10 Insider Preview (introduced v10.0.17110.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v6)
internetClientServer privateNetworkClientServer internetClient

StartAsync() StartAsync() StartAsync() StartAsync() StartAsync()

Starts an asynchronous upload operation.

public : IAsyncOperationWithProgress<UploadOperation, UploadOperation> StartAsync()
IAsyncOperationWithProgress<UploadOperation, UploadOperation> StartAsync() const;
public IAsyncOperationWithProgress<UploadOperation, UploadOperation> StartAsync()
Public Function StartAsync() As IAsyncOperationWithProgress( Of UploadOperation )( Of UploadOperation )
Windows.Networking.BackgroundTransfer.UploadOperation.startAsync().done( /* Your success and error handlers */ );




Thrown when a feature-specific HRESULT is returned from a method call.

This is the most common exception that is thrown by networking methods. An app should use the HRESULT from the exception to determine the cause of the error. For more information on specific errors, see the Error Codes section below.


Thrown when access is denied to a resource or feature. This exception occurs when an app doesn't have the required network capabilities set in the app manifest for the network operation requested.


Thrown when one of the arguments that are provided to a method is not valid.

If user-supplied input caused this exception, an app could inform the user and request new input.


Thrown when an operation is performed on a disposed object.


Thrown when insufficient memory is available to complete the operation.

An upload operation must be scheduled using one of the BackgroundUploader.CreateUpload, BackgroundUploader.CreateUploadAsync , or BackgroundUploader.CreateUploadFromStreamAsync methods before the StartAsync method is called.


Queuing up a large number of transfers on the main UI thread can result in degraded performance of your app's UI, even though the call is awaitable. If you are queuing up a large number of transfers, it is recommended that you call StartAsync on a background worker thread as in the following example.

operation = await Task.Run(() => { return myUploadOperation.StartAsync(); });
See Also

See Also