title: How to set the filename when downloading a file?
body: <p>I'm working on MVC 4. I have generated Excel file dynamically using following simple code. My hosting is on Azure.</p>
  
  <p>I have created a Root path and then try to save that Excel file.</p>
  
  <p>Problem is when my <code>ActionResult</code> method response comes back it is giving default popup to open a file but file name is having a GUID instead my provided file name.</p>
  
  <p>Excel file generation code:</p>
  
  <p>Microsoft.Office.Interop.Excel.Application xlApp = 
          new Microsoft.Office.Interop.Excel.Application();</p>
  
  <pre><code>// ...
  //Save
          LocalResource resource = RoleEnvironment.GetLocalResource("MyValue");
          string tempPath = resource.RootPath + "DemoFile.xls";
  return tempPath;
  </code></pre>
  
  <p>tempPath returns path like <code>C:\AppData\Local\dftmp\Resources\11a2435c-998c-4fe8-aa55-8bb42455b4ca\directory\DemoFile.xls</code>.</p>
  
  <p>The Download File popup does not give file name as <code>DemoFile</code> it <code>gives some GUID</code> why so?</p>
  
  <p><img src="https://i.stack.imgur.com/sQS8y.png" alt="enter image description here">   </p>
  
  <p><code>ActionResult</code> method code:</p>
  
  <pre><code>public ActionResult DownloadExcel() {
      string path = ExcelGenerationCode(fileName);
          Stream s = new FileStream(path, FileMode.Open, FileAccess.Read);
          return new FileStreamResult(s, "application/vnd.ms-excel");
      }
  </code></pre>
  
  <p>Also tried to give name property</p>
  
  <pre><code>public ActionResult DownloadExcel() {
      string path = ExcelGenerationCode(fileName);
          Stream s = new FileStream(path, FileMode.Open, FileAccess.Read);
          return new FileStreamResult(s, "application/vnd.ms-excel")
          {
              FileDownloadName = "myexcelFILE1.xls"
          };
      }
  </code></pre>
  
  <p>getting below error when give filename parameter.
  <img src="https://i.stack.imgur.com/u0k6Q.png" alt="enter image description here"></p>
  
  <p>i have plenty of space and memory.</p>