Monday, February 2, 2009

Export Word Document in ASP.NET

Here we are exporting the data from a grid to word,


Response.Clear();
Response.Buffer = true;
Response.AddHeader("Content-Disposition", "attachment;filename=Test.doc");
Response.ContentType = "application/ms-word";
StringWriter stringWriter = new StringWriter();
HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);
gvwEmployeeGrid.RenderControl(htmlTextWriter);
Response.Output.Write(stringWriter.ToString());
Response.Flush();
Response.End();


Make EventValidation to false for the page and also override VerifyRenderingInServerForm in code behind,


public override void VerifyRenderingInServerForm(Control control)
{

}

0 comments:

Post a Comment