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
Above answers helped me, this is what I ended up with:
public class DeleteFileAttribute : ActionFilterAttribute
{
public override void OnResultExecuted(ResultExecutedContext filterContext)
{
filterContext.HttpContext.Response.Flush();
var filePathResult = filterContext.Result as FilePathResult;
if (filePathResult != null)
{
System.IO.File.Delete(filePathResult.FileName);
}
}
}