cmrhema
cmrhema

Reputation: 981

Do we have any Equivalent of Response.AppendHeader in windows application

I came around this technique of converting datatable to excel http://www26.brinkster.com/mvark/dyna/downloadasexcel.html

Do we have any Equivalent of Response.AppendHeader in windows application in C#.

Regards Hema

Upvotes: 0

Views: 1822

Answers (1)

mvark
mvark

Reputation: 2105

The trick in the code sample that you have mentioned to dynamically generate an Excel file is based on the fact that documents can be converted from Word/Excel to HTML (File->Save As) and vice versa. Essentially a HTML page containing Office XML is created & in a web application a file download is triggered with the help of the following Response.AppendHeader statements -

Response.AppendHeader("Content-Type", "application/vnd.ms-excel");
Response.AppendHeader("Content-disposition", "attachment; filename=my.xls");

If you want to use this technique in a Winforms application, just save the string content as a text file and give the file an extension of ".xls". Instead of the last 3 lines in the sample's Page_Load method, replace it with this line -

System.IO.File.WriteAllText(@"C:\Report.xls", strBody);

HTH

Upvotes: 1

Related Questions