Skip to content
This repository has been archived by the owner on Oct 2, 2024. It is now read-only.

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

Closed
E3Solutions opened this issue Aug 14, 2017 · 2 comments
Closed

Comments

@E3Solutions
Copy link

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
Copy link

albel1205 commented Oct 17, 2017

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

@baywet
Copy link
Member

baywet commented Oct 2, 2024

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

@baywet baywet closed this as not planned Won't fix, can't repro, duplicate, stale Oct 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants