.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> ADO.NET >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Read html file and text file usign ASP.NET

Posted By:varun bansal       Posted Date: July 27, 2009    Points: 10    Category: ADO.NET    URL: http://www.dotnetspark.com  
 

The following code tell how to read Html and txt file in asp.net

Add main namespace
using System.IO;
Read html file
string file = Server.MapPath ("abc.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>";

Label1.Text = input;
Read text file
StreamReader sr = File.OpenText(Server.MapPath("abc.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();
Regards
Varun bansal
www.varunbansal007.blogspot.com


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend