本文介绍了MultipartFormDataStreamProvider清理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果文件发布到我的Web应用程序,那么我将通过 MultipartFormDataStreamStreamProvider.FileData
读取它们.
If files are posted to my webapp, then I read them via MultipartFormDataStreamProvider.FileData
.
我这样初始化提供程序:
I Initialize the provider like this:
string root = HttpContext.Current.Server.MapPath("~/App_Data");
var provider = new MultipartFormDataStreamProvider(root);
并且提供程序很好地将它们存储为〜App_Data/BodyPart_ {someguid}"但是,用完这些文件后,如何清理这些文件?
And the provider nicely stores them as "~App_Data/BodyPart_{someguid}"But how do I clean up those files after I'm done with them?
推荐答案
我知道这个问题很旧,但是发现删除临时文件的最佳方法是在处理它之后.
I know this question is old, but the best way I found to delete the temporary file was after processing it.
string root = HttpContext.Current.Server.MapPath("~/App_Data");
var provider = new MultipartFormDataStreamProvider(root);
foreach (var file in provider.Files)
{
// process file upload...
// delete temporary file
System.IO.File.Delete(file.LocalFileName);
}
这篇关于MultipartFormDataStreamProvider清理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!