Live Chat Icon For mobile
Live Chat Icon

How to read text file in ASP.NET

Platform: ASP.NET| Category: Files

Use namespace System.IO

VB.NET


Dim sr As StreamReader
sr = File.OpenText(Server.MapPath('1.txt'))
Dim strContents As String = sr.ReadToEnd()
’To display normal raw contents
Response.Write(strContents)

’To handle Carriage returns
Response.Write(strContents.Replace(vbCrLf, '<br>'))

sr.Close()

C#


StreamReader sr = File.OpenText(Server.MapPath('1.txt'));
string strContents = sr.ReadToEnd();
//To display normal raw contents
Response.Write(strContents);

//To handle Carriage returns
Response.Write(strContents.Replace('\n' , '<br>'));

sr.Close();

Share with

Share on twitter
Share on facebook
Share on linkedin

Related FAQs

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

Please submit your question and answer.