looping query - pulling back results?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kieth
    New Member
    • May 2010
    • 8

    looping query - pulling back results?

    hi,

    i have managed to put together a program that reads a file and if it finds the word "error" it brings back that line of details...

    unfortunately, it stops on that line...

    does anybody know how i get it to carry on through an entire log?

    this is my code so far

    Code:
    {
    	class Program
    	{
    		public static void Main(string[] args)
    		{
            try 
            {
                // Create an instance of StreamReader to read from a file.
                // The using statement also closes the StreamReader.
                using (StreamReader sr = new StreamReader(@"C:\Documents and Settings\kwareham01\Desktop\test.txt"))
                {
                    String line;
                    // Read and display lines from the file until the end of 
                    // the file is reached.
                    while ( (line = sr.ReadLine() ) != "" )
                    {
                    	
                    	if(line.IndexOf("error")!=-1) {
                      	
                    	Console.WriteLine(line);
                        Console.ReadLine();
                    	}
                    }
                }
            }
            catch (Exception e) 
            {
                // Let the user know what went wrong.
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(e.Message);
                Console.ReadLine();
            }
        }
    }
    }
    thanks
  • kieth
    New Member
    • May 2010
    • 8

    #2
    ignore post i've figured it out now

    thanks

    Comment

    Working...