title: Render Html view as Word document
body: <p>Below code converts returns an MVC view as a Word document, but it doesn't give the downloaded file a <code>.doc</code> extension.</p>
  
  <pre><code>public ActionResult ToWord()
  {
      var model = Logic.GetModel();
      string html = Utils.ViewToString(this, "MyView", model);
      return Content(html, "application/msword");
  }
  
  static string ViewToString(Controller controller, string viewName, object model)
  {
      controller.ViewData.Model = model;
      using (StringWriter sw = new StringWriter())
      {
          ViewEngineResult viewResult = ViewEngines.Engines.FindPartialView(controller.ControllerContext, viewName);
          ViewContext viewContext = new ViewContext(controller.ControllerContext, viewResult.View, controller.ViewData, controller.TempData, sw);
          viewResult.View.Render(viewContext, sw);
          return sw.ToString();
      }
  }
  </code></pre>
  
  <p>I have tried adding below code, but the extension appears to be ignored. Saving the document as <code>file.doc</code> makes Word behave correctly:</p>
  
  <pre><code>HttpContext.Response.AppendHeader("Content-Disposition", "wordFile.doc");
  </code></pre>
  
  <p>Any ideas how I can get extension added to the file?</p>