problem to reading multiple lines from txt page
-
hi! friends, i have .txt file. from this file, i retrieve the information contain it, and display in another page. my problem is that, i am not retrieve multiple lines from the page. because i have coded multiple
sr.readLine()
, which is not good. please guide me, how am i retrieve all the information from the page.
StreamReader sr = new StreamReader("c:\..\abc.txt);
string strline = "";
strline = sr.ReadLine();
strline = sr.ReadLine();
sr.Close();thanx and regards
-
hi! friends, i have .txt file. from this file, i retrieve the information contain it, and display in another page. my problem is that, i am not retrieve multiple lines from the page. because i have coded multiple
sr.readLine()
, which is not good. please guide me, how am i retrieve all the information from the page.
StreamReader sr = new StreamReader("c:\..\abc.txt);
string strline = "";
strline = sr.ReadLine();
strline = sr.ReadLine();
sr.Close();thanx and regards
-
hi! friends, i have .txt file. from this file, i retrieve the information contain it, and display in another page. my problem is that, i am not retrieve multiple lines from the page. because i have coded multiple
sr.readLine()
, which is not good. please guide me, how am i retrieve all the information from the page.
StreamReader sr = new StreamReader("c:\..\abc.txt);
string strline = "";
strline = sr.ReadLine();
strline = sr.ReadLine();
sr.Close();thanx and regards
Hi, one solution:
const string f = "TextFile1.txt"; // Declare new List. List<string> lines = new List<string>(); // Use using StreamReader for disposing. using (StreamReader r = new StreamReader(f)) { // Use while != null pattern for loop string line; while ((line = r.ReadLine()) != null) { // "line" is a line in the file. Add it to our List. lines.Add(line); } }
-
Hi, one solution:
const string f = "TextFile1.txt"; // Declare new List. List<string> lines = new List<string>(); // Use using StreamReader for disposing. using (StreamReader r = new StreamReader(f)) { // Use while != null pattern for loop string line; while ((line = r.ReadLine()) != null) { // "line" is a line in the file. Add it to our List. lines.Add(line); } }
-
hi! friends, i have .txt file. from this file, i retrieve the information contain it, and display in another page. my problem is that, i am not retrieve multiple lines from the page. because i have coded multiple
sr.readLine()
, which is not good. please guide me, how am i retrieve all the information from the page.
StreamReader sr = new StreamReader("c:\..\abc.txt);
string strline = "";
strline = sr.ReadLine();
strline = sr.ReadLine();
sr.Close();thanx and regards
Another solution:
string[] lines = File.ReadAllLines(@"c:\MyFile.Txt");
There are nearly always multiple ways to do anything in .NET!
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.