Reputation: 404
I'm trying to open an excel file that I wrote using epplus.
I'm opening it using this and it works in development server but not after publishing it.
System.Diagnostics.Process.Start(Server.MapPath("~\chart.xlsx"))
How can i open this excel sheet?
Upvotes: 0
Views: 1512
Reputation: 31248
Your code is trying to open the Excel file on the server. Even if you have Excel installed on the server, there probably won't be anyone sitting in front of the server to see it.
I suspect you want to open the file on the client:
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
Response.AppendHeader("Content-Disposition", "attachment;filename=chart.xlsx")
Response.WriteFile(Server.MapPath("~/chart.xlsx"))
Response.End()
You also need to bear in mind that there could be multiple users accessing your application at the same time. If you're generating the chart.xlsx
file dynamically, the file for one request could overwrite the file for another request. It would be better to save the file directly to the response:
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
Response.AppendHeader("Content-Disposition", "attachment;filename=chart.xlsx")
YourExcelPackage.SaveAs(Response.OutputStream)
Response.End()
Upvotes: 5