Click here to Skip to main content
15,557,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I working on web api core 3.1 I need to return export path direct without copying to memory so How to do that Please ?

How to return export path without copy to memory as below

return File(memory2, "text/plain", Path.GetFileName(exportPath));

meaning using exportPath instead of using memory2
exactly I need to return content file

What I have tried:

foreach (var m in mods)
                          List<InputExcel> inputmodulelist = new List<InputExcel>();
                          inputmodulelist = inputexcellist.Where(x => x.ModuleName == m).ToList();
                          var dtimport = DatatableConversion.ToDataTable(inputmodulelist);
                          DataTable dtexport = new DataTable();
                          dtexport = _deliveryService.LoadExcelToDataTable(_connectionString, dtimport);
                          ex.Export(dtexport, m, exportPath);
                  var memory2 = new MemoryStream();
                  using (var stream = new FileStream(exportPath, FileMode.Open))
                  memory2.Position = 0;
                  return File(memory2, "text/plain", Path.GetFileName(exportPath));
Updated 7-Sep-21 22:53pm

1 solution

Use the PhysicalFile[^] method:
return PhysicalFile(exportPath, "text/plain", Path.GetFileName(exportPath));
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900