Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
XML
protected void btnExportToWord_Click(object sender, EventArgs e)
 {


     string strBody = "<html>" +
    "<body>" +
        "<div>Your name is: <b>om   </b></div>" +
        "<table width=\"100%\" style=\"background-color:#cfcfcf;\"><tr><td>1st Cell body data</td><td>2nd cell body data</td></tr></table>" +
        "Ms Word document generated successfully." +
    "</body>" +
    "</html>";
     string fileName = "MsWordSample.doc";
     Response.AppendHeader("Content-Type", "application/msword");
     Response.AppendHeader("Content-disposition", "attachment; filename=" + fileName);
     Response.Write(strBody);
     Response.End();

}
Posted
Comments
Gihan Liyanage 5-Sep-14 7:38am    
From where you are trying to export?
Ratnamounika 5-Sep-14 7:41am    
My requirement is,on Button Click a word document should generate and download
Pheonyx 5-Sep-14 7:44am    
Where is your code to generate the file? or the path to the file which are you trying to attach to your response?

 
Share this answer
 
Comments
Gihan Liyanage 15-Sep-14 6:29am    
Did you got a solution from my support, I can see you have not accepted any answer.If you are ok with this answer plz accept it. Then any user having same problem can identified it has solved the problem..
Response.Clear();
Response.Charset = " ";
Response.ContentEncoding = System.Text.UnicodeEncoding.UTF8;
Response.Charset = "UTF-8";
Response.ContentType = "application/msword";
Response.Buffer = true;
Response.AddHeader("Content-Disposition", "attachment;filename=Individual.doc");
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