Showing posts with label ASP.Net MS word file creation. Show all posts
Showing posts with label ASP.Net MS word file creation. Show all posts

Saturday, February 18, 2012

Create MS Word Document using ASP.Net


Create Microsoft word document using ASP.NET and C#.

Here i have used string builder and filestream function to create Microsoft word document using ASP.Net and C# .


using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.IO;

public partial class css : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string strPath = "D://abc.doc";
        //Create stringBuilder to write formatted Text to word file
       
        StringBuilder strBuilder = new StringBuilder();
        strBuilder.Append("Hello world");
              
        FileStream fStream = File.Create(strPath);
        fStream.Close();
        StreamWriter sWriter = new StreamWriter(strPath);
        sWriter.Write(strBuilder);
        sWriter.Close();

    }

}