hi i have the following code:
private void Textparsing()
{
using (StreamReader sr = new StreamReader(Masterbuildpropertiespath))
{
String line;
line = sr.ReadLine();
while ((line != null))
{
if (line.StartsWith("Exec_mail"))
{
ExecmailCheckBox.IsChecked = true;
}
}
}
}
When i use this function, it seems that the application just hangs there without doing anything. Is this something wrong with the while loop here?
EDIT 1:
the code i am using now has the error: ‘System.IO.StreamReader’ does not contain a definition for ‘Readline’ and no extension method ‘Readline’ accepting a first argument of type ‘System.IO.StreamReader’ could be found
code:
private void Textparsing()
{
using (StreamReader sr = new StreamReader(Masterbuildpropertiespath))
{
while (sr.Peek() >= 0)
{
if (sr.Readline().StartsWith("Exec_mail"))
{
ExecmailCheckBox.IsChecked = true;
}
}
}
}
error is found in this line:
if (sr.Readline().StartsWith("Exec_mail"))
Use StreamReader.Peek() to determine the end of file:
EDIT:
I ran the code with a sample text file located at D:\aa.txt with 4 lines of text in it as:
Exec_mail
abcd
Exec_mail
efgh
Exec_mail
using this code:
And it showed yes three times.