Save a file as HTML

 

Step 1 : Save it as an HTML File
Step 2 : Use some 3rd party tool to convert it ( Temporary Solution )

Step 1 : Save it as an HTML File

1 @ First put the contents you need to write as an HTML file in to a div container

Ex :<div id="b" runat=server>
<table><tr> <td></td>
<td> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td> </tr> </table>
</div>

2 @ Include a hidden field

Ex :<input type="hidden" id="testing2" name="testing2" runat="server" />

3 @ Include a script at the end of the page

Ex :<script type="text/javascript" language="javascript">
document.getElementById("testing2").value= document.getElementById('b').innerHTML ;
</script>

4 @ Go to the code behind of the page . The above things has to do in the html part of the page

5 @ Suppose we are doing the conversion in a button click.And here we are writing the file as an html file.Let it be test.txt.We can write this in any format.Eg : test.html.. so lets do it

protected void Button1_Click(object sender, EventArgs e)
{
string a = testing2.Value;
StringBuilder htm = new StringBuilder();
htm.Append("<html><head><title>Untitled Page</title></head><body>");
htm.Append(a);
htm.Append("</body></html>");
System.IO.StreamWriter StreamWriter1 = new System.IO.StreamWriter(Server.MapPath("test.txt"));
StreamWriter1.WriteLine(htm);
StreamWriter1.Close();

}