0

I have a view that is rendered with ContentType of "application/msword". For users this appears as download file. Now, I would like to save this document server side. How could get I access the rendered document server side ?

Yahel
  • 37,023
  • 22
  • 103
  • 153
Zoliqa
  • 1,015
  • 2
  • 15
  • 36

2 Answers2

1
using (var stream = new MemoryStream())
using (var writer = new StreamWriter(stream))
{
    var viewContext =
        new ViewContext(
            filterContext.Controller.ControllerContext,
            vResult.View,
            vResult.ViewData,
            vResult.TempData,
            writer);

    vResult.View.Render(viewContext, writer);
    writer.Flush();
}
Zoliqa
  • 1,015
  • 2
  • 15
  • 36
0

On the server you could use a WebClient to fire an HTTP request to the url and download the file or download it in memory as a byte array.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928