Ejemplo n.º 1
0
        private async Task <bool> UploadFile(StorageFile localFile, string path)
        {
            bool result = false;
            var  _cts   = new CancellationTokenSource();

            CachedFileManager.DeferUpdates(localFile);
            try
            {
                var properties = await localFile.GetBasicPropertiesAsync();

                long BytesTotal = (long)properties.Size;

                using (var stream = await localFile.OpenAsync(FileAccessMode.Read))
                {
                    var targetStream = stream.AsStreamForRead();

                    IProgress <WebDavProgress> progress = new Progress <WebDavProgress>(ProgressHandler);
                    result = await client.Upload(path, targetStream, localFile.ContentType, progress, _cts.Token);
                }
            }
            catch (ResponseError e2)
            {
                ResponseErrorHandlerService.HandleException(e2);
            }

            // Let Windows know that we're finished changing the file so
            // the other app can update the remote version of the file.
            // Completing updates may require Windows to ask for user input.
            await CachedFileManager.CompleteUpdatesAsync(localFile);

            return(result);
        }