I want to delete a file immediately after download, how do I do it? I\'ve tried to subclass FilePathResult
and override the WriteFile
method where
overriding the OnResultExecuted method is probably the correct solution.. This method runs after the response is written.
public class DeleteFileAttribute : ActionFilterAttribute
{
public override void OnResultExecuted(ResultExecutedContext filterContext)
{
filterContext.HttpContext.Response.Flush();
// Delete file
}
}
Action code:
[DeleteFileAttribute]
public FileContentResult GetFile(int id)
{
//your action code
}