question

ahmedsalah-1628 avatar image
0 Votes"
ahmedsalah-1628 asked Viorel-1 answered

how to return export path without using copy to memory2 ?

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



dotnet-csharpdotnet-aspnet-core-webapi
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AgaveJoe avatar image
1 Vote"
AgaveJoe answered

I think you are looking for the following????

 return File(System.IO.File.ReadAllBytes(exportPath), "text/plain", System.IO.Path.GetFileName(exportPath));
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Viorel-1 avatar image
0 Votes"
Viorel-1 answered

Check this approach too:

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

However, if exportPath is a temporary file, you cannot delete it immediately.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.