I am trying to load 100 MB of Text file in rich text box, but the application gets hang or some times it gives out of memory exception.
I tried below
Case1: it is running for long time
fs = new FileStream(FileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
sr = new StreamReader(fs);
//rtxtFile.AppendText( sr.ReadToEnd());
while (!sr.EndOfStream)
{
rtxtFile.AppendText(sr.ReadLine() + System.Environment.NewLine);
}
Case2: out of memory exception
fs = new FileStream(FileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
sr = new StreamReader(fs);
rtxtFile.AppendText( sr.ReadToEnd());
with reagrds,
Vishnuvarthan.V
vishnuvarthan vPosted May 10, 2012, 5:35 AM
It is loaded successfully . I loded the file initially in the richtextbox i.e. after selecting the file. But again the problem continues.
i)when searching with keyword - memory out of exception occurs (Find method)
richTextBox1.Find(sSearchText, start, options); memory out of exception occurs (Find method)
ii) when i try to load the second file - memory out of exception occurs.
Is there any alternate to richtextbox control (open source)?
rsCodePosted May 9, 2012, 6:21 AM
let us know if that solves the issue.
Good Luck
vishnuvarthan vPosted May 9, 2012, 5:44 AM
rsCodePosted May 8, 2012, 11:43 AM
Have u tried the below line??
richTextBox1.Text = sr.ReadToEnd();
I have tried in my system with 100 mb text file.It works and loads within seconds.
But if I use while loop it will run for a long time because it reads line by line and takes time until it reaches the end of stream.
Regards
RS