Esempio n. 1
0
        private async Task UploadStorageItems(IEnumerable <IStorageItem> storageItems, string remotePath)
        {
            try
            {
                List <FileTransferInfo> filesToUpload = new List <FileTransferInfo>();
                foreach (var item in storageItems)
                {
                    if (item is StorageFile file)
                    {
                        filesToUpload.Add(new FileTransferInfo
                        {
                            File       = file,
                            RemotePath = Path.Combine(remotePath, file.Name)
                        });
                    }
                    else if (item is StorageFolder folder)
                    {
                        await FileTransferInfo.LoadFromLocalFolderAsync(folder, remotePath, filesToUpload);
                    }
                    else
                    {
                        System.Diagnostics.Debugger.Break();
                    }
                }

                await UploadFilesAsync(filesToUpload);
            }
            catch (Exception ex)
            {
                string message;
                message = string.Format("无法创建上传任务。错误信息:\n{0}", ex.Message);
                ContentDialog dialog = new ContentDialog()
                {
                    Content         = message,
                    CloseButtonText = "确定"
                };
                await dialog.ShowAsync();
            }
        }
Esempio n. 2
0
        private async void PanelMenuUploadFile_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string remotePath = currentAddress.LocalPath + currentAddress.Fragment;

                FileOpenPicker picker = new FileOpenPicker();
                picker.CommitButtonText = "上传";
                picker.FileTypeFilter.Add("*");
                var files = await picker.PickMultipleFilesAsync();

                if (files.Any())
                {
                    FileTransferInfo[] fileUploadList = new FileTransferInfo[files.Count];
                    for (int i = 0; i < files.Count; i++)
                    {
                        fileUploadList[i] = new FileTransferInfo
                        {
                            File       = files[i],
                            RemotePath = Path.Combine(remotePath, files[i].Name)
                        };
                    }
                    await UploadFilesAsync(fileUploadList);
                }
            }
            catch (Exception ex)
            {
                string        message = string.Format("创建上传任务失败。错误信息:\n{0}", ex.Message);
                ContentDialog dialog  = new ContentDialog
                {
                    Content         = message,
                    CloseButtonText = "确定"
                };
                await dialog.ShowAsync();
            }
        }