title: Return file from ASP.NET 5 Web API
body: <p>My previous question: <a href="https://stackoverflow.com/questions/34853072/how-to-return-file-from-asp-net-5-web-api/34856354#34856354">How to return file from ASP.net 5 web api</a></p>
  
  <p>I am trying to return a file as the response from Web API POST request. </p>
  
  <p>I'm using dnx451 framework and rc1-final build. Controller method: </p>
  
  <pre><code>[HttpPost("")]
  public ActionResult Post([FromBody]DocumentViewModel vm)
  {
      try
      {
          if (ModelState.IsValid)
          {
  
              var Document = _repository.GetDocumentByGuid(vm.DocumentGuid, User.Identity.Name);
              var Params = Helper.ClientInputToRealValues(vm.Parameters, Document.DataFields);
              var file = Helper.GeneratePdf(Helper.InsertValues(Params, Document.Content));
              FileStream stream = new FileStream(file,FileMode.Open);
  
              return File(stream, "application/pdf", "test.pdf");
  
          }
  
      }
      catch (Exception ex)
      {
          Response.StatusCode = (int)HttpStatusCode.BadRequest;
          return null;
      }
      Response.StatusCode = (int)HttpStatusCode.BadRequest;
      return null;
  
  }
  </code></pre>
  
  <p>As result I get a file with name "response". After saving it as pdf i try to open it, and it says it is damaged. Hope you can help me. I am using Postman as test client.</p>
  
  <p>Thanks</p>