MultipartFormDataStreamProvider Cleanup

后端 未结 2 1499
谎友^
谎友^ 2021-02-20 14:59

If files are posted to my webapp, then I read them via MultipartFormDataStreamProvider.FileData.

I Initialize the provider like this:

strin         


        
2条回答
  •  猫巷女王i
    2021-02-20 15:35

    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);
    }
    

提交回复
热议问题