How to delete file after download with ASP.NET MVC?

后端 未结 13 1014
执念已碎
执念已碎 2020-12-07 20:51

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

相关标签:
13条回答
  • 2020-12-07 21:56

    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)
    };
    
    0 讨论(0)
提交回复
热议问题