Hi Shyama,
Check this example. Now please take its reference and correct your code.
HTML
<asp:TextBox ID="txtFileName" runat="server" />
<div runat="server" id="dvCustomers">
<table border="1" cellpadding="0" cellspacing="0">
<th>
Id
</th>
<th>
Name
</th>
<th>
Country
</th>
<tr>
<td>
1
</td>
<td>
Mudassar Khan
</td>
<td>
India
</td>
</tr>
<tr>
<td>
2
</td>
<td>
Thomas Hardy
</td>
<td>
Ireland
</td>
</tr>
</table>
</div>
<br />
<asp:Button Text="Create" runat="server" OnClick="Create" />
Namespaces
C#
using System.IO;
VB.Net
Imports System.IO
Code
C#
protected void Create(object sender, EventArgs e)
{
string html = dvCustomers.InnerHtml;
string fileName = txtFileName.Text.Trim() + ".html";
string filePath = Server.MapPath("~/") + fileName;
StreamWriter objReader = null;
try
{
if (File.Exists(filePath))
{
File.Delete(filePath);
}
objReader = new StreamWriter(filePath);
objReader.Write(html);
}
finally
{
objReader.Close();
}
Response.Redirect(fileName);
}
VB.Net
Protected Sub Create(ByVal sender As Object, ByVal e As EventArgs)
Dim html As String = dvCustomers.InnerHtml
Dim fileName As String = txtFileName.Text.Trim() & ".html"
Dim filePath As String = Server.MapPath("~/") & fileName
Dim objReader As StreamWriter = Nothing
Try
If File.Exists(filePath) Then
File.Delete(filePath)
End If
objReader = New StreamWriter(filePath)
objReader.Write(html)
Finally
objReader.Close()
End Try
Response.Redirect(fileName)
End Sub
Screenshot