Write Data into a MS-Word Document

Lakhangarg
Posted by Lakhangarg under ASP.NET category on | Views : 2446
This Code Will Write the Text "My Name is Lakhan Pal Garg.\r\nI am a Senior Software Engineer.\r\nAnd i am Working in a Product Based Company." into a doc file.
A open/save dialog box will be visible at the end of the function. you can either directly open or can Save the doc file.

private void GenerateWordDoc()
{
string strContent = "My Name is Lakhan Pal Garg.\r\nI am a Senior Software Engineer.\r\nAnd i am Working in a Product Based Company.";
string attach = "attachment; filename=Lakhan.doc";
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Charset = "";

HttpContext.Current.Response.ContentType = "application/msword";
HttpContext.Current.Response.AddHeader("content-disposition", attach);
HttpContext.Current.Response.Write(strContent);
HttpContext.Current.Response.End();
HttpContext.Current.Response.Flush();
}

Comments or Responses

Login to post response