Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. problem to reading multiple lines from txt page

problem to reading multiple lines from txt page

Scheduled Pinned Locked Moved C#
helptutorial
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    annie_bel
    wrote on last edited by
    #1

    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

    D J OriginalGriffO 3 Replies Last reply
    0
    • A annie_bel

      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

      D Offline
      D Offline
      Dan Mos
      wrote on last edited by
      #2

      use sr.ReadToEnd() to get all the data in the txt file as a string.

      I bug

      1 Reply Last reply
      0
      • A annie_bel

        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

        J Offline
        J Offline
        JF2015
        wrote on last edited by
        #3

        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);
                }
            }
        
        A 1 Reply Last reply
        0
        • J JF2015

          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);
                  }
              }
          
          A Offline
          A Offline
          annie_bel
          wrote on last edited by
          #4

          Thanx a lot all of u. really it's very easy. Actually i just started dotnet. so, i was worried. again thanx

          1 Reply Last reply
          0
          • A annie_bel

            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

            OriginalGriffO Online
            OriginalGriffO Online
            OriginalGriff
            wrote on last edited by
            #5

            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.

            "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
            "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups