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
Try This. This will work properly.
public class DeleteFileAttribute : ActionFilterAttribute
{
public override void OnResultExecuted( ResultExecutedContext filterContext )
{
filterContext.HttpContext.Response.Flush();
string filePath = ( filterContext.Result as FilePathResult ).FileName;
File.Delete( filePath );
}
}