[英]File not being released after upload
使用Asp.Net MVC,我正在上傳一個zip文件,並使用以下方法將其解壓縮,由於該處理后我無法在Windows資源管理器中將其刪除,因此似乎仍附加了一個進程。
這是控制器的帖子:
[HttpPost]
public ActionResult ImportZip(HttpPostedFileBase zip)
{
try
{
if (zip == null)
throw new Exception("Please select a file to import");
var result = new ContentManagementImporter(EducorDbRepo).ImportZipFile(zip);
ViewData[ViewDataKeys.SuccessMessage] = result;
return View("Import");
}
catch (Exception ex)
{
SetViewError(ex);
return View("Import");
}
}
這是處理上傳文件的方法:
private static Dictionary<string, string> UnzipFiles(HttpPostedFileBase zipFile)
{
var files = new Dictionary<string, string>();
using (var archive = new ZipArchive(zipFile.InputStream))
{
foreach (var file in archive.Entries)
{
if (file == null)
continue;
using (var stream = file.Open())
using (var reader = new StreamReader(stream))
{
var markup = reader.ReadToEnd();
files.Add(file.Name, markup);
}
}
}
zipFile.InputStream.Close();
return files;
}
您可以在代碼中看到我無法關閉需要關閉的內容嗎,還是有其他原因?
服務器行為無法鎖定客戶端上的文件。 因此,我90%確信您看到的任何鎖定都是由瀏覽器本身造成的(因此不受您的控制)。
您可能需要考慮嘗試使用其他瀏覽器,然后看看會發生什么。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.