简体   繁体   English

上传后文件未释放

[英]File not being released after upload

Using Asp.Net MVC, I'm uploading a zip file and extracting it using the following method, and there seems to be a process still attached to it, as I cannot delete it in Windows Explorer after processing. 使用Asp.Net MVC,我正在上传一个zip文件,并使用以下方法将其解压缩,由于该处理后我无法在Windows资源管理器中将其删除,因此似乎仍附加了一个进程。

Here's the controller post: 这是控制器的帖子:

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

And here's the method that process the uploaded file: 这是处理上传文件的方法:

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

Can you see where in the code I'm failing to close something that needs to be closed, or is there another reason? 您可以在代码中看到我无法关闭需要关闭的内容吗,还是有其他原因?

The server behaviour can't lock files on the client. 服务器行为无法锁定客户端上的文件。 As such, I am 90% sure any locking you are seeing is caused by the browser itself (and thus outside your control). 因此,我90%确信您看到的任何锁定都是由浏览器本身造成的(因此不受您的控制)。

You may want to consider trying an alternate browser and seeing what happens. 您可能需要考虑尝试使用其他浏览器,然后看看会发生什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM