title: C# MVC 4: Create Word Document and download without saving in disk
body: <p>This probably has a very simple answer but i just can't find it.</p>
  
  <p>I have a project using C# MVC 4 using Microsoft.Office.Interop.Word 12</p>
  
  <p>In an action I try to dynamically create a Word file (using a database for the information) and then i want to download it. The file does not exist (it is created from scratch) and I don't want to save it in disk (it does not need to be saved because its content is dynamic).</p>
  
  <p>This is the code for now:</p>
  
  <pre><code>public ActionResult Generar(Documento documento)
  {
      Application word = new Application();
      word.Visible = false;
  
      object miss = System.Reflection.Missing.Value;
      Document doc = word.Documents.Add(ref miss, ref miss, ref miss, ref miss);
  
      Paragraph par = doc.Content.Paragraphs.Add(ref miss);
      object style = "Heading 1";
      par.Range.set_Style(ref style);
      par.Range.Text = "This is a dummy test";
  
      byte[] bytes = null;  // This is the part i need to get the bytes of the doc object
      doc.Close();
  
      word.Quit();
  
      return File(bytes, "application/octet-stream", "NewFile.docx");
  }
  </code></pre>