/// <inheritdoc/> public async Task <bool> CopyAsync(IOneDriveStorageFolder destinationFolder, string desiredNewName = null, CancellationToken cancellationToken = default(CancellationToken)) { if (destinationFolder == null) { throw new ArgumentNullException(nameof(destinationFolder)); } if (OneDriveItem.Name == "root") { throw new Microsoft.Graph.ServiceException(new Error { Message = "Could not copy the root folder" }); } if (string.IsNullOrEmpty(desiredNewName)) { desiredNewName = this.OneDriveItem.Name; } OneDriveParentReference parentReference = new OneDriveParentReference(); if (destinationFolder.OneDriveItem.Name == "root") { parentReference.Parent.Path = "/drive/root:/"; } else { parentReference.Parent.Path = destinationFolder.OneDriveItem.ParentReference.Path + $"/{destinationFolder.OneDriveItem.Name}"; } parentReference.Name = desiredNewName; var copyRequest = ((IGraphServiceClient)Provider).Drive.Items[OneDriveItem.Id].Copy(desiredNewName); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, copyRequest.Request().RequestUrl); request.Headers.Add("Prefer", "respond-async"); var content = JsonConvert.SerializeObject(parentReference); request.Content = new StringContent(content, Encoding.UTF8, "application/json"); await Provider.AuthenticationProvider.AuthenticateRequestAsync(request).ConfigureAwait(false); var response = await Provider.HttpProvider.SendAsync(request, HttpCompletionOption.ResponseContentRead, cancellationToken).ConfigureAwait(false); return(response.IsSuccessStatusCode); }
/// <summary> /// Upload large file. /// </summary> /// <param name="folder">The destination folder</param> /// <returns>Task to support await of async call.</returns> public static async Task UploadLargeFileAsync(IOneDriveStorageFolder folder) { try { if (folder != null) { var selectedFile = await OpenLocalFileAsync(); if (selectedFile != null) { using (var localStream = await selectedFile.OpenReadAsync()) { Shell.Current.DisplayWaitRing = true; // If the file exceed the Maximum size (ie 4MB) var largeFileCreated = await folder.UploadFileAsync(selectedFile.Name, localStream, CreationCollisionOption.GenerateUniqueName, 320 * 1024); } } } } catch (OperationCanceledException ex) { await OneDriveSampleHelpers.DisplayMessageAsync(ex.Message); } catch (ServiceException graphEx) { await OneDriveSampleHelpers.DisplayMessageAsync(graphEx.Error.Message); } catch (Exception ex) { await OneDriveSampleHelpers.DisplayMessageAsync(ex.Message); TrackingManager.TrackException(ex); } finally { Shell.Current.DisplayWaitRing = false; } }
private async Task NavigateToFolderAsync(IOneDriveStorageItem item) { progressRing.IsActive = true; try { var currentFolder = await _currentFolder.GetFolderAsync(item.Name); var items = await currentFolder.GetFoldersAsync(100); if (items.Count > 0) { LstFolder.ItemsSource = items; _currentFolder = currentFolder; } } catch (ServiceException ex) { await OneDriveSampleHelpers.DisplayOneDriveServiceExceptionAsync(ex); } finally { progressRing.IsActive = false; } }
/// <summary> /// Create a new folder in the current folder /// </summary> /// <param name="folder">Destination folder where to create the new folder</param> /// <returns>Task to support await of async call.</returns> public static async Task NewFolderAsync(IOneDriveStorageFolder folder) { if (folder != null) { Shell.Current.DisplayWaitRing = true; try { string newFolderName = await OneDriveSampleHelpers.InputTextDialogAsync("New Folder Name"); if (!string.IsNullOrEmpty(newFolderName)) { await folder.CreateFolderAsync(newFolderName, CreationCollisionOption.GenerateUniqueName); } } catch (ServiceException ex) { await OneDriveSampleHelpers.DisplayOneDriveServiceExceptionAsync(ex); } finally { Shell.Current.DisplayWaitRing = false; } } }
private void LstFolder_ItemClick(object sender, ItemClickEventArgs e) { _destinationFolder = e.ClickedItem as IOneDriveStorageFolder; }
public FoldersPickerControl(List <IOneDriveStorageFolder> folders, IOneDriveStorageFolder rootFolder) { this.InitializeComponent(); _folders = folders; _currentFolder = _rootFolder = rootFolder; }
public static async Task <IOneDriveStorageFolder> OpenFolderPicker(string title, IOneDriveStorageFolder rootFolder) { FoldersPickerControl folderPicker = new FoldersPickerControl(await rootFolder.GetFoldersAsync(100), rootFolder); ContentDialog dialog = new ContentDialog { Content = folderPicker, Title = title, PrimaryButtonText = "Ok" }; if (await dialog.ShowAsync() == ContentDialogResult.Primary) { return(folderPicker.SelectedFolder); } else { return(null); } }
/// <summary> /// Send an httpRequest to get an Onedrive Item /// </summary> /// <param name="provider">OneDriveClient Provider</param> /// <param name="request">Http Request to execute</param> /// <param name="destinationFolder">Destination folder</param> /// <param name="desiredNewName">New name</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> for the request.</param> /// <returns>a OneDrive item or null if the request fail</returns> internal static async Task <bool> MoveAsync(this IBaseClient provider, HttpRequestMessage request, IOneDriveStorageFolder destinationFolder, string desiredNewName, CancellationToken cancellationToken) { OneDriveParentReference rootParentReference = new OneDriveParentReference(); if (destinationFolder.OneDriveItem.Name == "root") { rootParentReference.Parent.Path = "/drive/root:/"; } else { rootParentReference.Parent.Path = destinationFolder.OneDriveItem.ParentReference.Path + $"/{destinationFolder.OneDriveItem.Name}"; } rootParentReference.Name = desiredNewName; var content = JsonConvert.SerializeObject(rootParentReference); request.Content = new StringContent(content, Encoding.UTF8, "application/json"); await provider.AuthenticationProvider.AuthenticateRequestAsync(request).ConfigureAwait(false); var response = await provider.HttpProvider.SendAsync(request, HttpCompletionOption.ResponseContentRead, cancellationToken).ConfigureAwait(false); return(response.IsSuccessStatusCode); }