C# – new ActionResult that can render the view generated and send contents via email


I was wondering if it were possible to write a file FileResult that worked something like this.

public ActionResult Generate(int id)
    //Fill Model
    string ViewName = "template1";    

    return new FileResult(ViewName, @"c:\save"+ id +".txt");

where it would take the model, and combine it with the view to give you the output that would normally be displayed to the screen but instead just save it with the filename specified.

Note: This file will be saved on the webserver

Best Solution

I don't think it is possible. You can specify the filename and the mime type but that is it. Imagine the security vulnerability caused by what you are proposing.