Click here to Skip to main content
16,011,870 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I have used the following code to convert the html table to excel and it works fine but the default save file type is Web Page(*.htm; *.html) and I want it to be xls what should I do

HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"
HttpContext.Current.Response.AddHeader("content-disposition",
"attachment;filename=Test.xls")
HttpContext.Current.Response.Write(strHTML)
HttpContext.Current.Response.End()
Posted

1 solution

C#
HttpContext.Current.Response.ContentType = "application/x-download";
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + System.IO.Path.GetFileName(fileInfo.Name));
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.WriteFile(fileInfo.FullName);
HttpContext.Current.Response.End();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900