Read Large File
-
That is way too much data to display in a TextBox. You need to rethink how you want to display the data. It's not possible to see more than a few kilobytes worth of text on the screen at once anyway.
Despite everything, the person most likely to be fooling you next is yourself.
Hi Guffa My Problem not TextBox. You suppose I want show data from file line by line into TextBox. My problem is volume of file
Best Regards, Reza Shojaee
-
Hi Guffa My Problem not TextBox. You suppose I want show data from file line by line into TextBox. My problem is volume of file
Best Regards, Reza Shojaee
You can read the file in another thread, this way your GUI should stay respondent. But I still wouldn't read it completely into memory, you will run into
OutOfMemoryException
s rather quickly. I'd suggest to read smaller chunks of the file as needed. regards -
You can read the file in another thread, this way your GUI should stay respondent. But I still wouldn't read it completely into memory, you will run into
OutOfMemoryException
s rather quickly. I'd suggest to read smaller chunks of the file as needed. regardsA) It's only 100mb. He shouldn't be running out of memory. B) When memory fills up, Windows pages to disk. He shouldn't be running out of memory.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 -
Hi everybody I have a problem for open large file in C#. While I want to open file with 100 MByte size(for example) and read its contents and show in the TextBox, program hanged. If you know any solution about mentioned matter, I will become very happy for your assistance. Thank you
Best Regards, Reza Shojaee
A string can theoretically only hold 2,147,483,647 characters. However, on a 32-bit OS, you never have that much contiguous memory available, so you'll probably never be able to create a string that large. Beyond that, no single array or structure can contain more than 1 billion items. If you're running a 64-bit OS, you will realize larger strings, but you still might not be able to allocate their full size unless you have 4-8gb of RAM. So, your problem is fragmented memory. With .Net, I'm not sure there's much you can do about it beyond allocating the string at program startup and hope you have enough unfragmented memory at that point. I would also use a
StringBuilder
object instead of a string because the constructor for aStringBuilder
allows you to specify the size of the object, and you can put atry/catch
block around the constructor call to make sure the framework didn't have any allocation problems."Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001modified on Sunday, August 10, 2008 7:23 AM
-
Hi everybody I have a problem for open large file in C#. While I want to open file with 100 MByte size(for example) and read its contents and show in the TextBox, program hanged. If you know any solution about mentioned matter, I will become very happy for your assistance. Thank you
Best Regards, Reza Shojaee
Hi my friend I think my problem with StreamReader solved
StreamReader sr = new StreamReader("c:\\1.psd"); string line; while ((line = sr.ReadLine()) != null)
thank you for your helpingBest Regards, Reza Shojaee
-
Hi my friend I think my problem with StreamReader solved
StreamReader sr = new StreamReader("c:\\1.psd"); string line; while ((line = sr.ReadLine()) != null)
thank you for your helpingBest Regards, Reza Shojaee
Also you can use this :
List<string> list = new List<string>();
using (StreamReader sr = new StreamReader(openFileDialog1.FileName))
{
//Read lines
while (sr.Peek() >= 0)
list.Add(sr.ReadLine());
} -
Also you can use this :
List<string> list = new List<string>();
using (StreamReader sr = new StreamReader(openFileDialog1.FileName))
{
//Read lines
while (sr.Peek() >= 0)
list.Add(sr.ReadLine());
} -
Hi Guffa My Problem not TextBox. You suppose I want show data from file line by line into TextBox. My problem is volume of file
Best Regards, Reza Shojaee
Reza Shojaee wrote:
My Problem not TextBox. You suppose I want show data from file line by line into TextBox. My problem is volume of file
Then I don't understand your question. What is the problem exactly? What error message do you get?
Despite everything, the person most likely to be fooling you next is yourself.
-
Hi everybody I have a problem for open large file in C#. While I want to open file with 100 MByte size(for example) and read its contents and show in the TextBox, program hanged. If you know any solution about mentioned matter, I will become very happy for your assistance. Thank you
Best Regards, Reza Shojaee
You rarely need to have an entire file in memory all at once; what are you trying to do?
-
Or simply:
string[] list = File.ReadAllLines(openFileDialog1.FileName);
Despite everything, the person most likely to be fooling you next is yourself.
Yeah you're right