Example #1
0
        private async void createFolderToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FormInputDialog dialog = new FormInputDialog("Create Folder", "New folder name:");
            var             result = dialog.ShowDialog();

            if (result == System.Windows.Forms.DialogResult.OK && !string.IsNullOrEmpty(dialog.InputText))
            {
                try
                {
                    var folderToCreate = new DriveItem {
                        Name = dialog.InputText, Folder = new Folder()
                    };
                    var newFolder =
                        await this.graphClient.Drive.Items[this.SelectedItem.Id].Children.Request()
                        .AddAsync(folderToCreate);

                    if (newFolder != null)
                    {
                        MessageBox.Show("Created new folder with ID " + newFolder.Id);
                        this.AddItemToFolderContents(newFolder);
                    }
                }
                catch (ServiceException exception)
                {
                    PresentServiceException(exception);
                }
                catch (Exception exception)
                {
                    PresentServiceException(exception);
                }
            }
        }
        private async void createFolderToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FormInputDialog dialog = new FormInputDialog("Create Folder", "New folder name:");
            var             result = dialog.ShowDialog();

            if (result == System.Windows.Forms.DialogResult.OK && !string.IsNullOrEmpty(dialog.InputText))
            {
                try
                {
                    var folderToCreate = new Item {
                        Name = dialog.InputText, Folder = new Folder()
                    };
                    var newFolder =
                        await this.oneDriveClient.Drive.Items[this.SelectedItem.Id].Children.Request()
                        .AddAsync(folderToCreate);

                    if (newFolder != null)
                    {
                        MessageBox.Show("Created new folder with ID " + newFolder.Id);
                        this.AddItemToFolderContents(newFolder);
                    }
                }
                catch (OneDriveException oneDriveException)
                {
                    if (oneDriveException.IsMatch(OneDriveErrorCode.InvalidRequest.ToString()))
                    {
                        MessageBox.Show(
                            "Please enter a valid folder name.",
                            "Invalid folder name",
                            MessageBoxButtons.OK);

                        dialog.Dispose();
                        this.createFolderToolStripMenuItem_Click(sender, e);
                    }
                    else
                    {
                        PresentOneDriveException(oneDriveException);
                    }
                }
                catch (Exception exception)
                {
                    PresentOneDriveException(exception);
                }
            }
        }
        private async void createFolderToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FormInputDialog dialog = new FormInputDialog("Create Folder", "New folder name:");
            var result = dialog.ShowDialog();
            if (result == System.Windows.Forms.DialogResult.OK && !string.IsNullOrEmpty(dialog.InputText))
            {
                try
                {
                    var folderToCreate = new Item { Name = dialog.InputText, Folder = new Folder() };
                    var newFolder =
                        await this.oneDriveClient.Drive.Items[this.SelectedItem.Id].Children.Request()
                            .AddAsync(folderToCreate);

                    if (newFolder != null)
                    {
                        MessageBox.Show("Created new folder with ID " + newFolder.Id);
                        this.AddItemToFolderContents(newFolder);
                    }
                }
                catch(OneDriveException oneDriveException)
                {
                    if (oneDriveException.IsMatch(OneDriveErrorCode.InvalidRequest.ToString()))
                    {
                        MessageBox.Show(
                            "Please enter a valid folder name.",
                            "Invalid folder name",
                            MessageBoxButtons.OK);

                        dialog.Dispose();
                        this.createFolderToolStripMenuItem_Click(sender, e);
                    }
                    else
                    {
                        PresentOneDriveException(oneDriveException);
                    }
                }
                catch (Exception exception)
                {
                    PresentOneDriveException(exception);
                }
            }
        }