Esempio n. 1
0
        private async void UploadButton_Click(object sender, EventArgs e)
        {
            var fileToUpload = SelectLocalFile();
            var data         = await OneDriveApi.UploadFile(fileToUpload, "");

            JsonResultTextBox.Text = data.OriginalJson;
        }
Esempio n. 2
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            if (comboBoxFileName.Text.Trim().Length < 1)
            {
                return;
            }

            _fileName = comboBoxFileName.Text;
            string parentId = string.Empty;

            if (_roots.Count > 0)
            {
                parentId = _roots.Peek();
            }
            try
            {
                labelInfo.Text = "Uploading...";
                Cursor         = Cursors.WaitCursor;
                _api.UploadFile(_path, _pathId, Path.GetFileName(_fileName), _content);
                Cursor       = Cursors.Default;
                DialogResult = DialogResult.OK;
            }
            catch (Exception exception)
            {
                labelInfo.Text = string.Empty;
                Cursor         = Cursors.Default;
                MessageBox.Show(exception.Message);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Allows picking a file which will be uploaded to the OneDrive root
        /// </summary>
        private async void UploadButton_Click(object sender, EventArgs e)
        {
            var fileToUpload = SelectLocalFile();

            // Reset the output field
            JsonResultTextBox.Text = $"Starting upload{Environment.NewLine}";

            // Define the anonynous method to respond to the file upload progress events
            EventHandler <OneDriveUploadProgressChangedEventArgs> progressHandler = delegate(object s, OneDriveUploadProgressChangedEventArgs a) { JsonResultTextBox.Text += $"Uploading - {a.BytesSent} bytes sent / {a.TotalBytes} bytes total ({a.ProgressPercentage}%){Environment.NewLine}"; };

            // Subscribe to the upload progress event
            OneDriveApi.UploadProgressChanged += progressHandler;

            // Upload the file to the root of the OneDrive
            var data = await OneDriveApi.UploadFile(fileToUpload, await OneDriveApi.GetDriveRoot());

            // Unsubscribe from the upload progress event
            OneDriveApi.UploadProgressChanged -= progressHandler;

            // Display the result of the upload
            JsonResultTextBox.Text = data != null ? data.OriginalJson : "Not available";
        }