i am editing the excel file in angular and passing the file to .net 6 for saving using below code
public async Task<IActionResult> Save([FromForm] SaveSettings saveSettings)//,string PhysicalFolder)
using (ExcelEngine excelEngine = new ExcelEngine())
IApplication application = excelEngine.Excel;
string PhysicalFolderId = saveSettings.FileName.Split(',');
Guid DocumentId = Guid.Parse(saveSettings.FileName.Split(','));
var path = await _context.Documents.Where(x => x.Id == DocumentId).FirstOrDefaultAsync();
var filePath = Path.Combine(_pathHelper.ContentRootPath, _pathHelper.DocumentPath, path.Path);
// Convert Spreadsheet data as Stream
Stream fileStream = Workbook.Save<Stream>(saveSettings);
IWorkbook workbook = application.Workbooks.Open(fileStream);
FileStream outputStream = new FileStream(filePath, FileMode.Create);
catch (Exception ex)
return Ok(ex); //NotFound(new ObjectResult("Failure"));
return Ok("File Saved");
but after saving the file. File cannot be accessed after saving saying ' IOException: The process cannot access the file 'D:\filemanager\Main\SourceCode\DotnetCoreRESTApiSQLServerProvider\ShareDrive.API\Documents\4b352b37-332a-40c6-ab05-e38fcf109719\4fb7f532-4ff0-4843-a302-651907a5af8f.xlsx' because it is being used by another process.'
Hi Tirathpal ,
We have checked your reported issue and we suspect that the cause of the issue is due to the file stream is not properly disposed in your server side save method. Hence, we suggest you to properly dispose the output stream in save method. For more clarification regarding open/save the excel file in the server. Please find the link below.
We also attach a sample along with local Web API sample for your kind reference. Please do refer to it.
Stackblitz Sample: https://stackblitz.com/edit/angular-8ysbbu?file=app.component.ts
Note: Run the API sample before performing the Save or Load action on the spreadsheet.
Kindly get back to us if you need further assistance regarding.
NOTE: If this post is helpful, please mark it as an answer so that other members can locate it more quickly.