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?