title: Certain big '.xlsx' extension files failed to open after downloaded via SftpClient
body: <p>I am trying to download file from a remote linux server to my local computer using SftpClient.</p>
  <p>Here is my code to download the file</p>
  <pre><code>        public MemoryStream DownloadFile2(string path)
          {
              var connectionInfo = _taskService.GetBioinformaticsServerConnection();
              MemoryStream fileStream = new MemoryStream();
                          
              using (SftpClient client = new SftpClient(connectionInfo))
              {
                  client.ConnectionInfo.Timeout = TimeSpan.FromSeconds(200);
                  client.Connect();
  
                  
                  client.DownloadFile(path, fileStream);
                  fileStream.Seek(0, SeekOrigin.Begin);
                  
                  var response = new MemoryStream(fileStream.GetBuffer());
                  return fileStream;
              }
          }
  </code></pre>
  <p>And here is the controller that called above method.</p>
  <pre><code>        public FileResult DownloadFile(string fullPath, string fileName)
          {
              if (!string.IsNullOrEmpty(fileName))
              {
                  fullPath = string.Concat(fullPath, &quot;/&quot;, fileName);
              }
              var ms = _reportAPI.DownloadFile2(fullPath);
  
              var ext = Path.GetExtension(fullPath);
              if (ext == &quot;.xlsx&quot;)
              {
                  return File(ms, &quot;application/vnd.openxmlformats-officedocument.spreadsheetml.sheet&quot;, fileName);
              }
              return File(ms, &quot;application/octet-stream&quot;, fileName);            
          }
  </code></pre>
  <p>I have manage to do it for most of the files, however for certain large '.xlsx' extension files, when I tried to open it, for some reason, I received below error.</p>
  <p><a href="https://i.stack.imgur.com/5Wk6N.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5Wk6N.png" alt="enter image description here" /></a></p>
  <p>If I am on IISExpress, I still manage to open it after I clicked on 'Yes' button, but if I'm using the normal IIS, it failed to open the file after clicked on 'Yes' button.</p>
  <p>For other type of files or smaller excel files, it works as expected.</p>
  <p>Any idea how can I modified my code to solve this issue?</p>