title: How to convert a file into byte array in memory?
body: <p>Here is my code:</p>
  
  <pre><code> public async Task&lt;IActionResult&gt; Index(ICollection&lt;IFormFile&gt; files)
   {
      foreach (var file in files)
          uploaddb(file);   
  
      var uploads = Path.Combine(_environment.WebRootPath, "uploads");
      foreach (var file in files)
      {
          if (file.Length &gt; 0)
          {
              var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
  
              await file.SaveAsAsync(Path.Combine(uploads, fileName));
          }
      }
  }
  </code></pre>
  
  <p>Now I am converting this file into byte array using this code:</p>
  
  <pre><code>var filepath = Path.Combine(_environment.WebRootPath, "uploads/Book1.xlsx");
  byte[] fileBytes = System.IO.File.ReadAllBytes(filepath);
  string s = Convert.ToBase64String(fileBytes);
  </code></pre>
  
  <p>And then I am uploading this code into my nosql database.This is all working fine but the problem is i don't want to save the file. Instead of that i want to directly upload the file into my database. And it can be possible if i can just convert the file into byte array directly without saving it.</p>
  
  <pre><code>public async Task&lt;IActionResult&gt; Index(ICollection&lt;IFormFile&gt; files)
  {
      foreach (var file in files)
          uploaddb(file);   
      var uploads = Path.Combine(_environment.WebRootPath, "uploads");
      foreach (var file in files)
      {
          if (file.Length &gt; 0)
          {
              var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
  
  ///Code to Convert the file into byte array
  }
  </code></pre>