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 preferred a solution which returned an HttpResponseMessage
. I liked the simplicity of Risord's answer, so I created a stream in the same manner. Then, instead of returning a File
, I set the HttpResponseMessage.Content
property to a StreamContent
object.
var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.None, 4096, FileOptions.DeleteOnClose);
return new HttpResponseMessage()
{
Content = new StreamContent(fs)
};