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
I have posted this solution in https://stackoverflow.com/a/43561635/1726296
public ActionResult GetFile()
{
string theFilename = ""; //Your actual file name
Response.Clear();
Response.AddHeader("content-disposition", "attachment; filename="); //optional if you want forced download
Response.ContentType = "application/octet-stream"; //Appropriate content type based of file type
Response.WriteFile(theFilename); //Write file to response
Response.Flush(); //Flush contents
Response.End(); //Complete the response
System.IO.File.Delete(theFilename); //Delete your local file
return new EmptyResult(); //return empty action result
}