13.07.2015 Views

ASP.NET 3.5: A Beginner's Guide - www.mustafaof.com

ASP.NET 3.5: A Beginner's Guide - www.mustafaof.com

ASP.NET 3.5: A Beginner's Guide - www.mustafaof.com

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

382<strong>ASP</strong>.<strong>NET</strong> <strong>3.5</strong>: A Beginner’s <strong>Guide</strong>When you enter data into a text file using the WriteLine() method, it automaticallyenters a line break, so when you use the ReadLine(), it knows what text is consideredto be a separate line. Text entered in other ways marks the end of the line with either of theother two acceptable markers that ReadLine() can find. The following web site examplereads the “Pauper Database” (pauperDataBase.txt), and it shows how you can retrieve anddisplay the “records” from any text file:<strong>ASP</strong>.<strong>NET</strong> FileReader.aspxRead Text FileC# FileReader.aspx.csusing System;using System.IO;public partial class FileRead : System.Web.UI.Page{private StreamReader readMe;private String readLn;protected void Page_Load(object sender, EventArgs e){try{using (readMe = new StreamReader(MapPath("pauperDataBase.txt"))){while ((readLn = readMe.ReadLine()) != null){Label1.Text += readLn + "";

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!