Avoid stuck while reading a large textfile
-
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.
-
Sure, but how to determine actual file block and block size? StreamReader and TextReader don't support a method to do it.
-
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. -
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. -
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.