hey....i got some problem in ReadLines method

  string filePath = @"c:\Users\Fish\Desktop\fyp-coding\Data.txt";
                    string line;

                 if (File.Exists(filePath))
                    {
                        StreamReader file = null;
                        try
                        {
                            file = new StreamReader(filePath);



                            while ((line= file.ReadLine())!= null)
                            {
                                textBox7.Text = line;

                            }

                        }

                        finally
                        {
                            if (file != null)
                            file.Close();
                        }

                    }

When i use this coding...it only show the last line to me. I want show the previous line, how to do it?

string filePath = @"c:\Users\Fish\Desktop\fyp-coding\Data.txt";
String[] myLines = File.ReadAllLines(filePath);
textBox7.Text = myLines[myLines.Length - 2];

what is different between readLine, readAllLine and readToEnd...?

ReadLine gets one line from the file
ReadAllLines reads all the lines and returns an array of strings.
ReadToEnd reads the entire file returning it as one string.

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.