Pages

Men

rh

7/09/2012

Exporting data from Gridview to Word Document in C#

protected void btnExportWord_Click(object sender, EventArgs e)
{
    Response.Clear();
    Response.Buffer = true;
    Response.AddHeader("content-disposition",      
                        "attachment;filename=SearchInfo.doc");
    Response.Charset = "";
    Response.ContentType = "application/vnd.ms-word ";
    StringWriter sw= new StringWriter();
    HtmlTextWriter hw = new HtmlTextWriter(sw);
    dgSearch.AllowPaging = false;
    dgSearch.DataBind();
    dgSearch.RenderControl(hw);
    Response.Output.Write(sw.ToString());
    Response.Flush();
    Response.End();
}

No comments :

Post a Comment