/// <summary> /// Upload a stream to the server. /// </summary> /// <param name="path">relative or absolute uri to the location where the file should be uploaded to.</param> /// <param name="fileName">name for the uploaded file.</param> /// <param name="inputStream">Stream that contains the upload's content.</param> /// <param name="option">an enum to specify the overwrite behavior if a file with the same name already exists.</param> /// <param name="ct">a token that is used to cancel the upload operation.</param> /// <param name="progress">an object that is called to report the upload's progress.</param> /// <returns>A Task object representing the asynchronous operation.</returns> public Task <LiveOperationResult> BackgroundUploadAsync( string path, string fileName, IInputStream inputStream, OverwriteOption option, CancellationToken ct, IProgress <LiveOperationProgress> progress) { if (string.IsNullOrEmpty(path)) { throw new ArgumentException( "path", String.Format(CultureInfo.CurrentUICulture, ResourceHelper.GetString("UrlInvalid"), "path")); } if (string.IsNullOrEmpty(fileName)) { throw new ArgumentException( "fileName", String.Format(CultureInfo.CurrentUICulture, ResourceHelper.GetString("InvalidNullOrEmptyParameter"), "fileName")); } if (inputStream == null) { throw new ArgumentNullException( "inputStream", String.Format(CultureInfo.CurrentUICulture, ResourceHelper.GetString("InvalidNullParameter"), "inputStream")); } ApiOperation op = new TailoredUploadOperation( this, this.GetResourceUri(path, ApiMethod.Upload), fileName, inputStream, option, progress, null); return(this.ExecuteApiOperation(op, ct)); }
public void TestExecuteMethod() { WebRequestFactory.Current = new TestWebRequestFactory(); LiveConnectClient connectClient = new LiveConnectClient(new LiveConnectSession()); Uri requestUri = new Uri("http://foo.com"); string fileName = "fileName.txt"; IStorageFile inputFile = new StorageFileStub(); OverwriteOption option = OverwriteOption.Overwrite; IProgress <LiveOperationProgress> progress = new Progress <LiveOperationProgress>(); SynchronizationContextWrapper syncContext = SynchronizationContextWrapper.Current; var tailoredUploadOperation = new TailoredUploadOperation( connectClient, requestUri, fileName, inputFile, option, progress, syncContext); }