title: How to get a response "stream" from an action in MVC3/Razor?
body: <p>I am using MVC3, .NET4, C#.</p>
  
  <p>I need to create some XHTML using a Razor View. I do this via an Action.</p>
  
  <pre><code>    public ActionResult RenderDoc(int ReportId)
      {
          //A new document is created.
  
          return View();
      }
  </code></pre>
  
  <p>I then need to take the output from this and convert it to a Word Doc. I am using a 3rd party component to do this and it expects a "stream" or a "file" for the XHTML source that is read in for conversion to a DOC, like the following:</p>
  
  <pre><code>document.Open(MyXhtmlStream,FormatType.Html,XHTMLValidationType.Transitional);
  </code></pre>
  
  <p><strong>My Question:</strong></p>
  
  <p>What would be a good way to call the "RenderDoc" Action and obtain the result as a stream to feed into "MyXhtmlStream".</p>
  
  <p>Many thanks.</p>
  
  <p><strong>EDIT: I have had another idea !!!</strong></p>
  
  <p>1) Render the View within the action to create a String(XHTMLString). I have seen a method to do this on SO.</p>
  
  <p>2) Create a MemoryStream and put this string into it.</p>
  
  <pre><code>Stream MyStream = New MemoryStream("XHTMLString and encoding method");
  </code></pre>
  
  <p><strong>EDIT2: Based on Darin's answer</strong></p>
  
  <p>I need to clasyify a little further, and I hope to do this via tweaking Darin's code for my purpose.</p>
  
  <pre><code> public class XmlDocumentResult : ActionResult
   {
    private readonly string strXhtmlDocument;
    public XmlDocumentResult(string strXhtmlDocument)
    {
      this.strXhtmlDocument = strXhtmlDocument;
    }
  
    public override void ExecuteResult(ControllerContext context)
    {
      WordDocument myWordDocument = new WordDocument();
      var response = context.HttpContext.Response;
      response.ContentType = "text/xml";
      myWordDocument.Open(response.OutputStream, FormatType.Html, XHTMLValidationType.Transitional);
    }
   }
  </code></pre>
  
  <p>The above is closer to what I need. Note the 3rd Party WordDocument type. So there is still the issue of how I get the "strXhtmlDocument" into the "Response.OutputStream?</p>