C#解压后删除.ZIP文件 [英] C# Deleting a .ZIP file after unzipping

查看:1398
本文介绍了C#解压后删除.ZIP文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是Ionic.Zip.dll从DotNetZip库,我想删除ZIP文件它完成后解压缩,但我不能设法做到这一点。

I am using the Ionic.Zip.dll from the DotNetZip library and I'm trying to delete the ZIP file after it finishes unzipping, but I can't manage to do it.

下面的代码是我目前有:

Here is the code I have currently:

    using (ZipFile zip = ZipFile.Read(nextVersion + ".zip"))
{
    zip.ExtractAll(Directory.GetCurrentDirectory(), ExtractExistingFileAction.OverwriteSilently);

    try
    {
        File.Delete(nextVersion + ".zip");
    }
    catch (Exception)
    {
        MessageBox.Show("Could not delete ZIP!");
        Environment.Exit(1);
    }
}



我在做什么错在这里?

What am I doing wrong here?

推荐答案

您所得到的异常,因为该文件仍处于打开状态,当您尝试删除。移动 File.Delete 来后使用块。

You are getting the exception because the file is still open when you try to delete. Move the File.Delete to after the using block.

这篇关于C#解压后删除.ZIP文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆