Reading large file using byte[] gives error
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/6094306/hash-sha1-large-files-over-2gb-in-c-sharp">Hash SHA1 large files (over 2gb) in C#</a>  </p>
</blockquote>



<p>I have a large file in size of terms and it gives me error  "Exception of type 'System.OutOfMemoryException' was thrown."</p>

<p>Anyone is having idea or solution for resolve this issue. Please help.
Sample code....</p>

<pre><code> private string GetSha1()
    {
        string filePath = txtFileName.Text;
        byte[] filebytes = System.IO.File.ReadAllBytes(filePath);
        byte[] hashValue;
        SHA1Managed hashString = new SHA1Managed();

        string hex = "";

        hashValue = hashString.ComputeHash(filebytes);
        foreach (byte x in hashValue)
        {
            hex += String.Format("{0:x2}", x);
        }
        return hex;
    }
</code></pre>

<p>I am getting exception at line below in above code....</p>

<pre><code>   byte[] filebytes = System.IO.File.ReadAllBytes(filePath);
</code></pre>

<p>The filePath is having file which is having size > 500MB.</p>
