Live Chat Icon For mobile
Live Chat Icon

How to read a html file in ASP.NET

Platform: ASP.NET| Category: Files

Use namespace System.IO
VB.NET

Dim file As String = Server.MapPath('temp.html')
Dim sr As StreamReader
Dim fi As New FileInfo(file)
Dim input As String = '<pre>'
If File.Exists(file) Then
   sr = File.OpenText(file)
   input += Server.HtmlEncode(sr.ReadToEnd())
   sr.Close()
End If
input += '</pre>'
Me.Label1.Text = input

C#

string file = Server.MapPath ('temp.html');
StreamReader sr;
FileInfo fi = new FileInfo(file);
string input = '<pre>';
if(File.Exists(file))
{
	sr = File.OpenText(file);
	input += Server.HtmlEncode(sr.ReadToEnd());
	sr.Close();
}
input += '</pre>';
this.Label1.Text = input;

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.