We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Edit file xlsx from Onedrive

Thread ID:





148443 Oct 19,2019 05:30 PM UTC Oct 23,2019 01:48 PM UTC UWP 1
Tags: XlsIO
Phan Minh Dang Khoa
Asked On October 19, 2019 05:30 PM UTC

I tried to edit a file on Ondrive via Microsoft Graph by downloading it for editing then uploading it again.
I encountered 2 problems as follows

"System.ArgumentException: 'Update mode requires a stream with read, write, and seek capabilities.'" for this code below.

ExcelEngine excelEngine = new ExcelEngine();
IApplication application = excelEngine.Excel;         
application.UseFastRecordParsing = true;
var stream = await graphClient.Me.Drive.Items["F90FCCBAC810EFDB!41667"].Content
IWorkbook workbook = await application.Workbooks.OpenAsync(stream);

I tried to upload a file successfully but it was empty.

using (ExcelEngine excelEngine = new ExcelEngine())
                FileOpenPicker openPicker = new FileOpenPicker();
                openPicker.SuggestedStartLocation = PickerLocationId.Desktop;
                StorageFile inputStorageFile = await openPicker.PickSingleFileAsync();
                Stream fileStream = (await inputStorageFile.OpenReadAsync()).AsStreamForRead();
                IWorkbook workbook = await excelEngine.Excel.Workbooks.OpenAsync(fileStream);
                workbook.Version = ExcelVersion.Excel2016;
                MemoryStream outputStream = new MemoryStream();
                await workbook.SaveAsAsync(outputStream);
                await graphClient.Me.Drive.Root.ItemWithPath(inputStorageFile.Name).Content

So how to solve these problems?

Konduru Keerthi Konduru Ravichandra Raju [Syncfusion]
Replied On October 23, 2019 01:48 PM UTC

Hi Phan, 

Greetings from Syncfusion. 

We have tried to reproduce the mentioned issues and found solution to resolve them. Please find the details below. 

"System.ArgumentException: 'Update mode requires a stream with read, write, and seek capabilities.'" for this code below. 
We request you to copy the stream to MemoryStream and set stream.Postion = 0; before loading the file into IWorkbook, to resolve the issue. 

Code Snippet:  

ExcelEngine excelEngine = new ExcelEngine(); 
IApplication application = excelEngine.Excel; 
application.UseFastRecordParsing = true; 
var stream = await graphClient.Me.Drive.Root.ItemWithPath("Sample.xlsx").Content.Request().GetAsync(); 
stream.Position = 0; 
MemoryStream file = new MemoryStream(); 
file.Position = 0; 
IWorkbook workbook = await application.Workbooks.OpenAsync(file); 
I tried to upload a file successfully but it was empty. 
We request you to set the stream position as 0 here also, before uploading the file to resolve the issue. 

Code Snippet: 

outputStream.Position = 0; 
await graphClient.Me.Drive.Root.ItemWithPath("Sample.xlsx").Content.Request().PutAsync<DriveItem>(outputStream); 

The sample we have tried at our end can be downloaded from the following link. 

Note: Please add the ApplicationID and use valid file name then execute the sample. 

Kindly try this and let us know if the issue is resolved. 



This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon