title: c# Asp.NET MVC downloading excel file using FileStreamResult
body: <p>I need to build a method, that will receive model, build excel from it (building and receiving part is done without problems) and then export (let user download it) using memory stream (without saving it on the server). I am new to ASP.NET and MVC so i found guide and built this as a tutorial project:</p>
  
  <pre><code>    public FileResult Download()
      {
          Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
  
          Microsoft.Office.Interop.Excel.Workbook xlWorkBook;
          Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet;
  
          object misValue = System.Reflection.Missing.Value;
  
          xlWorkBook = xlApp.Workbooks.Add(misValue);
          xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
  
          xlWorkSheet.Cells[1, 1] = "ID";
          xlWorkSheet.Cells[1, 2] = "Name";
          xlWorkSheet.Cells[2, 1] = "1";
          xlWorkSheet.Cells[2, 2] = "One";
          xlWorkSheet.Cells[3, 1] = "2";
          xlWorkSheet.Cells[3, 2] = "Two";
  
  
          var path = "C:\\Work-Work\\TestFolder\\XCLbuildTry1\\csharp-Excel.xls";
          xlWorkBook.SaveAs(path);
          xlWorkBook.Close(true, misValue, misValue);
          xlApp.Quit();
  
          Marshal.ReleaseComObject(xlWorkSheet);
          Marshal.ReleaseComObject(xlWorkBook);
          Marshal.ReleaseComObject(xlApp);
          return File(path, "application/vnd.ms-excel", "WidgetData.xlsx");
      }
  </code></pre>
  
  <p>Now i need to change this code to make this method sent my excel file without saving my excel file on server. I have tried to google some guides and answers here, on stack, but for now i cant find a solution, which i can implement.</p>
  
  <p>I think i should use <code>FileStreamResult</code>, but all guides give no particular information about creating and inserting my file into stream.</p>