Write Data into a MS-Word Document

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();
}


Please find the attached Output doc file.


Attachments

  • Output (30460-15752-Lakhan.doc)
  • Comments

    No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: