title: Error: Cannot access a closed file when converting imagefile into bytes
body: <p><a href="https://i.stack.imgur.com/D06eE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/D06eE.png" alt="enter image description here"></a>Whenever converting the imagefile into bytes we <em>got an error</em> like </p>
  
  <blockquote>
    <p>cannot access a closed file</p>
  </blockquote>
  
  <p>Please help me in order to overcome this</p>
  
  <pre><code>private byte[] ConvertToBytes(HttpPostedFileBase file)
  {
      byte[] imageBytes = null;
      BinaryReader reader = new BinaryReader(file.InputStream);
  
      imageBytes = reader.ReadBytes((int)file.ContentLength);
  
      return imageBytes;
  }
  </code></pre>