title: Download excel file in C#
body: <p>I have written an excel interop code to generate excel sheet report.The Report is generated and saved in a folder. After this I want to download the same file and I have written a code in the same application for downloading. File format is .xlsx. I am getting the following the error while downloading.</p>
  
  <pre><code>Cannot open the file, file fotmat may be different or file may be corrected.
  </code></pre>
  
  <p>But if I go to the drive directly I can open the same file.</p>
  
  <p><strong>downloading code</strong>:</p>
  
  <pre><code>private void DownloadFile(string getpathfromappconfig, string FileName)
  {
      string path = @getpathfromappconfig + "\\" + FileName + ".xlsx";
      System.IO.FileInfo file = new System.IO.FileInfo(path);
      string Outgoingfile = FileName + ".xlsx"; 
      if (file.Exists)
      { 
          Response.Clear();
          Response.AddHeader("Content-Disposition", "attachment; filename=" + Outgoingfile);
          Response.AddHeader("Content-Length", file.Length.ToString());
          Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
          Response.WriteFile(file.FullName);
  
      }
      else
      {
          Response.Write("This file does not exist.");
      }
  
  }
  </code></pre>
  
  <p>Can somebody help me to solve this?</p>