Hi members,
I am using EP Plus for my export to excel function, for my export function, I will need to have 2 saveas, 1st saveas which is a save dialogue to allow user open/save/saveas and my 2nd saveas to allow the excel file to be saved directly into the specified folder in the server as a backup copy.
Thus my issue here is that my 2nd saveas does not work (no error popup during debug, no files generated either for 2nd saveas).Please advice. thanks!
ExcelPackage package = new ExcelPackage(); ...... ....... ..... codes for loading data table ..... .... ..... var filename = @"REPORT_" + datetime.ToString("dd-MM-yyyy_hh-mm-ss") + ".xlsx";
The below codes works (my 1st saveas for user to choose to 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 below code does not work(my 2nd saveas to save file directly into server): string path = @"C:\Users\testacc\Desktop\Test\" + filename +";"; Stream stream = File.Create(path); package.SaveAs(stream); stream.Close(); byte[] data = File.ReadAllBytes(path);