I am using EPPlus to export to Excel. I need to have 2 SaveAs, 1st SaveAs, which is a save dialog that allows the Open / Save / SaveAs user and my second SaveAs to allow saving the Excel file directly to the specified folder on the server as a backup.
So my problem here is that my second SaveAs is not working (error pop-up during debugging, no files are generated for the second SaveAs).
I ask for advice. Thanks!
ExcelPackage package = new ExcelPackage(); ..... code for loading data table ..... var filename = @"REPORT_" + datetime.ToString("dd-MM-yyyy_hh-mm-ss") + ".xlsx";
Below are the codes (my 1st option is SaveAs for the user who must choose Open / Save / SaveAs):
Response.Clear(); package.SaveAs(Response.OutputStream); Response.AddHeader("content-disposition", "attachment; filename=" + filename + ";"); Response.Charset = ""; Response.ContentType = "application/vnd.xlsx"; Response.End();
The following code does not work (my second SaveAs to save the file directly to the server):
string path = @"C:\Users\testacc\Desktop\Test\" + filename +";"; Stream stream = File.Create(path); package.SaveAs(stream); stream.Close(); byte[] data = File.ReadAllBytes(path);
source share