.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> ASP.NET Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Write Data into a MS-Word Document

Posted By:Lakhan Pal Garg       Posted Date: June 30, 2010    Points: 10    Category: ASP.NET Controls    URL: http://www.dotnetspark.com  

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

Thanks

Lakhan Pal Garg


     

Further Readings:

Responses
Author: Peter         Company URL: http://www.dotnetspark.com
Posted Date: July 20, 2010

Easiest way to writing data to word using c#, I use it long time, name Spire.Doc, may help to you.

http://www.e-iceblue.com/Introduce/word-for-net-introduce.html
Author: Hannah         Company URL: http://www.dotnetspark.com
Posted Date: December 31, 2013

I am using Aspose.Words for .NET Library for managing my word documents including reading, writing, editing and converting my word docs to other formats. Try it, i hope it will help you solve your problem.

http://www.aspose.com/.net/word-component.aspx

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend