Rahul Chaudhari
Rahul Chaudhari

Reputation: 148

Programmatically insert data to word file and save in asp.net

i have one asp.net application , and i want to insert header and some text to word file programmatically. then insert gridview data in same word file and then save here is code

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 , gridview data is inserting in that word doc file, but before gridview i want insert some text in to same file, please help......

Upvotes: 3

Views: 1181

Answers (1)

Spider man
Spider man

Reputation: 3330

Add the following line

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

before

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

Upvotes: 3

Related Questions