title: C# - Read in a large (150MB) text file into a Rich Text Box
body: <p>I'm trying to read in a 150mb text file into a Rich Text box.</p>
  
  <p>Currently, I am using a StreamReader to iterate through each line in the file, appending every line to a StringBuilder instance.</p>
  
  <p>This works for smaller files, but I get a System.OutOfMemory exception when trying to read large files.</p>
  
  <p>I don't see any problems with reading a 150mb file - there is plenty of physical memory and that's well within the Windows 32-bit application address space.</p>
  
  <p>If anyone here has any idea how to do this, It would be greatly appreciated.</p>
  
  <p>I'll attach my code at the end.</p>
  
  <p>Thanks.</p>
  
  <pre><code>StringBuilder sb = new StringBuilder();
  using (StreamReader sr = new StreamReader(fileLocation))
  {
     string line;
     while ((line = sr.ReadLine()) != null)
     {
        sb.AppendLine(line);
     }
      }
  
  return sb;
  </code></pre>