title: How to Download File
body: <p>I have been following these links all listed below, i found the best way to write this SMALL create Excel and Download function. ( Using EPPlus for Excel )</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/3604562/download-file-of-any-type-in-asp-net-mvc-using-fileresult">Download file of any type in Asp.Net MVC using FileResult?</a> + <a href="https://stackoverflow.com/questions/1080442/how-to-convert-an-stream-into-a-byte-in-c">How to convert an Stream into a byte[] in C#?</a></li>
  <li><a href="http://www.kristofclaes.be/blog/2011/11/18/using-a-filestreamresult-with-a-memorystream-in-asp-net-mvc-3/" rel="nofollow noreferrer">Using a FileStreamResult with a MemoryStream in ASP.NET MVC 3</a></li>
  <li><a href="http://haacked.com/archive/2008/05/10/writing-a-custom-file-download-action-result-for-asp.net-mvc.aspx" rel="nofollow noreferrer">Writing A Custom File Download Action Result For ASP.NET MVC</a></li>
  </ul>
  
  <p>It runs through the code perfectly without error every time I run this but does not "Kick out" the file to be downloaded ( in a save as dialogue or w/e ).</p>
  
  <pre><code>public ActionResult ShowReport()
      {
          using (var stream = new MemoryStream())
          {
  
              ExcelPackage pck = new ExcelPackage();
              var ws = pck.Workbook.Worksheets.Add("Sample1");
  
              ws.Cells["A1"].Value = "Sample 1";
              ws.Cells["A1"].Style.Font.Bold = true;
              var shape = ws.Drawings.AddShape("Shape1", eShapeStyle.Rect);
              shape.SetPosition(50, 200);
              shape.SetSize(200, 100);
              shape.Text = "Sample 1 text text text";
  
              var fileDownloadName = "sample.xlsx";
              var contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";//System.Net.Mime.MediaTypeNames.Application.Octet
              var fileStream = new MemoryStream();
              pck.SaveAs(fileStream);
              fileStream.Position = 0;
  
              var fsr = new FileStreamResult(fileStream, contentType);
              fsr.FileDownloadName = fileDownloadName;
  
              byte[] fileBytes = ReadToEnd(fileStream);
              string fileName = "example";
              return File(fileBytes, contentType, fileName);
          }
      }
  </code></pre>
  
  <blockquote>
    <p><strong>What am I doing wrong / missing? - Must i write that Dialogue myself?</strong></p>
  </blockquote>
  
  <p>PN: I have also attempted this way</p>
  
  <pre><code> byte[] fileBytes = ReadToEnd(fileStream);
   string fileName = "example";
   return File(fileBytes, contentType, fileName);
  </code></pre>
  
  <p>ofcourse i had to figure out how to convert Stream to Byte but it also did not show anything.</p>
  
  <p><strong>Image of Chrome's Network Development Tool</strong>
  <img src="https://i.stack.imgur.com/Rw0vW.png" alt="enter image description here">
  <em>Sorry about the small image ( if you can't see it scroll in with ctl+MouseWheel ) if your in a supporting browswer.</em></p>