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. Avoid stuck while reading a large textfile

Avoid stuck while reading a large textfile

Scheduled Pinned Locked Moved C#
questionhelptutorialannouncement
7 Posts 3 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.
  • S Offline
    S Offline
    Seraphin
    wrote on last edited by
    #1

    While reading a large textfile with, I am going to implement a Progressbar. My question is how to determine the MAX value for this progressbar? So I can update the progressbar dynamically, while application is reading textfile.

    G 1 Reply Last reply
    0
    • S Seraphin

      While reading a large textfile with, I am going to implement a Progressbar. My question is how to determine the MAX value for this progressbar? So I can update the progressbar dynamically, while application is reading textfile.

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      Get the size of the file before you open it. --- b { font-weight: normal; }

      S 1 Reply Last reply
      0
      • G Guffa

        Get the size of the file before you open it. --- b { font-weight: normal; }

        S Offline
        S Offline
        Seraphin
        wrote on last edited by
        #3

        Sure, but how to determine actual file block and block size? StreamReader and TextReader don't support a method to do it.

        G 1 Reply Last reply
        0
        • S Seraphin

          Sure, but how to determine actual file block and block size? StreamReader and TextReader don't support a method to do it.

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          Block size? What do you mean? --- b { font-weight: normal; }

          S 1 Reply Last reply
          0
          • G Guffa

            Block size? What do you mean? --- b { font-weight: normal; }

            S Offline
            S Offline
            Seraphin
            wrote on last edited by
            #5

            File fIn = new File ("C:\\dotNET Projects\\Namespaces\\EnumFiles\\ReadMe.txt"); StreamReader strm = fIn.OpenText(); // continue reading until end of file string sLine; do { sLine = strm.ReadLine(); AddItem(sLine); } while (sLine != null); strm.Close(); Look at the code posted above. After sLine = strm.Readline, I want update the progressbar value but don't know the MAX value of this one before.

            D 1 Reply Last reply
            0
            • S Seraphin

              File fIn = new File ("C:\\dotNET Projects\\Namespaces\\EnumFiles\\ReadMe.txt"); StreamReader strm = fIn.OpenText(); // continue reading until end of file string sLine; do { sLine = strm.ReadLine(); AddItem(sLine); } while (sLine != null); strm.Close(); Look at the code posted above. After sLine = strm.Readline, I want update the progressbar value but don't know the MAX value of this one before.

              D Offline
              D Offline
              Dan Neely
              wrote on last edited by
              #6

              Get the size of the file in bytes, divide by two to get the number of chars. Finally use sLine.Length to get the number of chars you just read in.

              G 1 Reply Last reply
              0
              • D Dan Neely

                Get the size of the file in bytes, divide by two to get the number of chars. Finally use sLine.Length to get the number of chars you just read in.

                G Offline
                G Offline
                Guffa
                wrote on last edited by
                #7

                Dividing the size by two to the the number of chars only works if the textfile is saved as 16 bit unicode. Most text files are ANSI or UTF-8, which uses 8 bit encoding. --- b { font-weight: normal; }

                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