I have a block of code which gets a file and appends require data as shown below:
var srBuilder = new StringBuilder();
using (var file = new StreamReader(document.FullSourcePath, Encoding.ASCII))
{
while (!file.EndOfStream)
{
var bytess = new char[numBytes];
file.ReadBlock(bytess , 0, bytess.Length);
srBuilder.Append(buff);
}
document.Document += srBuilder.ToString(); ////Exception occures here
}
But when file is more than 200 MB then its throwing OutofMemoryException.
What i thought is to make length of string builder to zero as below:
while (!file.EndOfStream)
{
srBuilder.Length = 0; //// Here
var bytess = new char[numBytes];
file.ReadBlock(bytess , 0, bytess.Length);
srBuilder.Append(buff);
}
Is it best solution or anything else is required?