Edit file xlsx from Onedrive
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
.Request()
.GetAsync();
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;
openPicker.FileTypeFilter.Add(".xlsx");
openPicker.FileTypeFilter.Add(".xls");
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
.Request()
.PutAsync<DriveItem>(outputStream);
}
So how to solve these problems?
SIGN IN To post a reply.
1 Reply
KK
Konduru Keerthi Konduru Ravichandra Raju
Syncfusion Team
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.
|
Query |
Answer | |
|
"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:
| |
|
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:
|
The sample we have tried at our end can be downloaded from the following link.
Sample Link: https://www.syncfusion.com/downloads/support/forum/148443/ze/03-add-msgraph1181232979.zip
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.
Regards,
Keerthi.
SIGN IN To post a reply.
- 1 Reply
- 2 Participants
-
PM Phan Minh Dang Khoa
- Oct 19, 2019 05:30 PM UTC
- Oct 23, 2019 01:48 PM UTC