15 February 2014

How to generate a new html page on the server using asp.net?


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

namespace adi.Web
{
    public partial class WebForm2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            using (StreamWriter sw = new StreamWriter(Server.MapPath("fileName.html")))
            using (HtmlTextWriter writer = new HtmlTextWriter(sw))
            {
                writer.RenderBeginTag(HtmlTextWriterTag.Html);

                writer.RenderBeginTag(HtmlTextWriterTag.Head);
                writer.Write("Head Contents");
                writer.RenderEndTag();

                writer.RenderBeginTag(HtmlTextWriterTag.Body);
                writer.Write("Body Contents");
                writer.RenderEndTag();

                writer.RenderEndTag();
            }
        }
    }
}

No comments:

Post a Comment