OneDrive / onedrive-sdk-csharp

OneDrive SDK for C#! https://dev.onedrive.com
Other
293 stars 143 forks source link

Microsoft.Graph.ServiceException When uploading document to OneDrive SDK #234

Closed E3Solutions closed 1 month ago

E3Solutions commented 7 years ago

Getting this error after the recent 2.0.7 update: Exception of type 'Microsoft.Graph.ServiceException' was thrown.

Code: // Create the excel file moExcelFile.SaveXls(tempfile); // Convert temp file to stream object Stream stream = new System.IO.FileStream(tempfile, System.IO.FileMode.Open);

            string strOneDriveFileName = txtFileName.Text;
            string ext = Path.GetExtension(txtFileName.Text);
            if (String.IsNullOrEmpty(ext))
            {
                strOneDriveFileName += ".xls";
            }
            else
            {
                // Just remove whatever extension the user entered and append the correct extension.
                // This way we won't get any file type errors.
                strOneDriveFileName = strOneDriveFileName.Replace(ext, "");
                strOneDriveFileName += ".xls";
            }

            var targetFolder = this.CurrentOneDriveFolder;
            using (stream)
            {
                if (stream != null)
                {
                    string folderPath = targetFolder.ParentReference == null
                        ? "/drive/items/root:"
                        : targetFolder.ParentReference.Path + "/" + Uri.EscapeUriString(targetFolder.Name);
                    var uploadPath = folderPath + "/" + Uri.EscapeUriString(System.IO.Path.GetFileName(strOneDriveFileName));

                    try
                    {
                        ShowWork(true);
                        var uploadedItem =
                            await
                                this.oneDriveClient.ItemWithPath(uploadPath).Content.Request().PutAsync<Item>(stream);

                        AddItemToFolderContents(uploadedItem);
                        ShowWork(false);
                    }
                    catch (Exception exception)
                    {
                        clsErrorHandler.LogException(exception, "", "", "ucOneDriveBrowser", "SaveExcelFileToOneDrive", "", 0, true);
                    }
                }
            }

This has been working for quite a long without any issues. Now it seams a recent update has broken the PutAsync(stream) method.

I tried updating my solution to the latest version of the Microsoft.OneDrive.Sdk, but that did not work. Please advise.

albel1205 commented 7 years ago

I got the same issue when using the PutAsync method, but it works well if I manually create HTTP request. Please advise

baywet commented 1 month ago

Thank you for reaching out and for your patience. This SDK is being officially deprecated. See #259 for more information