Insert data programmatically into word file and save in asp.net

I have one asp.net application and I want to programmatically insert a title and text into a text file. then paste the gridview data into the same word file and then save the code here

protected void btnPrint_Click(object sender, EventArgs e)
{
    GridView1.AllowPaging = false;
    GridView1.DataBind();
    Response.ClearContent();
    Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "Customers.doc"));
    Response.Charset = "";
    Response.ContentType = "application/ms-word";
    StringWriter sw = new StringWriter();
    HtmlTextWriter htw = new HtmlTextWriter(sw);
    GridView1.RenderControl(htw);
    Response.Write(sw.ToString());
    Response.End();



}

      

now the gridview data is inserted into this word doc file, but before the gridview, I want to insert some text in one file, please help ......

+3


source to share


1 answer


Add the following line

Response.Write("enter your text here");  

      



before

GridView1.RenderControl(htw);
Response.Write(sw.ToString());

      

+3


source







All Articles