質問

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 ?

役に立ちましたか?

解決

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();
}

他のヒント

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top