ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,157 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I working on web api asp.net core 3.1 I need to return export path direct without copying to memory so How to do that Please ?
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))
{
stream.CopyTo(memory2);
}
memory2.Position = 0;
return File(memory2, "text/plain", Path.GetFileName(exportPath));
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
I think you are looking for the following????
return File(System.IO.File.ReadAllBytes(exportPath), "text/plain", System.IO.Path.GetFileName(exportPath));
Check this approach too:
return File(exportPath, "text/plain", Path.GetFileName(exportPath));
However, if exportPath is a temporary file, you cannot delete it immediately.