hi,
to read from a notepad i hv used the following code.
bt the problem is, it will not read the next line.
so how to read line by line.....

using (StreamReader sr = new StreamReader("c: \\key.txt"))
            {
              string s = sr.ReadLine();
              //etc.
               Console.WriteLine(s);//its showing the output
               string[] variables = s.Split(' ');
               float fvalue = float.Parse(variables[0]);
               Console.WriteLine(fvalue);
            }

You need a "while" loop.
something like:

//Open file here

   while(!sr.EndOfStream)
   {
      string s = sr.ReadLine();
      //...
   }

   /// close file here

With a using clause you don't have to worry about closing a file. The compiler infers that for you and takes the appropriate actions!

Found an old code snippet, Here goes.

static void Main(string[] args)
        {
            string line;

            try
            {
                StreamReader sr = new StreamReader(new FileStream("C:\\Techdata.txt", FileMode.Open));

                line = sr.ReadLine();
                while (line != null)
                {
                    Console.WriteLine(line);
                    line = sr.ReadLine();
                }
                sr.Dispose();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.ReadKey();
        }

Well, you need it to only stop reading when the document is over so use a loop of some sort. A while loop is the best.

Hey Sidd, let us know if this resolved your issue?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.