Generate HTML Document from Code Behind Using .Net C#


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

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string Name = "Alpesh D.Maniya";
        StringBuilder sb = new StringBuilder();
        sb.Append("<html><head><meta charset='utf-8'/><style>ul li{list-style:none;margin-top:3px;margin-bottom:3px;}h1{font-size: 23px;margin-bottom: 0px;margin-top: 0px;font-weight: normal;font-family: Arial;}h2{margin: 3px;margin-left: 0px;font-size: 16px;}h3{margin: 3px;font-size: 16px;}h4{margin: 3px;margin-left: 0px;font-size: 13px;}h5{margin: 3px;font-size: 11px;font-weight: normal;font-family: Arial;}</style></head>");
        sb.Append("<body style='text-align: center;margin:auto;margin-top:0px;margin-bottom:5px;'>");
        sb.Append(Name);
        sb.Append("</body>");

        StreamWriter sw1 = new StreamWriter(@"C:\Users\Alpesh.Maniya\Desktop\TestDocs.html");
        
        sw1.Write(sb);
        sw1.Flush();
        sw1.Close();
        sw1.Dispose();
        
    }
}

Comments

Popular posts from this blog

Create Short URL using C#