c# ZipFile.CreateFromDirectory - 进程无法访问文件 "path_to_the_zip_file_created.zip",因为它正被另一个进程使用

标签 c# .net

基本代码:

string startPath = @"C:\intel\logs";
string zipPath = @"C:\intel\logs-" + DateTime.Now.ToString("yyyy_dd_M-HH_mm_ss") + ".zip";
ZipFile.CreateFromDirectory(startPath, zipPath);

Error: the process cannot access the file "path_to_the_zip_file_created.zip" because it is being used by another process.

上述设置在我安装了 Visual Studio 的 Windows 7 上运行良好,但在 Windows Server 2008R2 上运行时出现上述错误消息。

我检查了防病毒日志,它没有阻止应用程序,也没有锁定创建的 zip 文件。

最佳答案

//WRONG
ZipFile.CreateFromDirectory("C:\somefolder", "C:\somefolder\somefile.zip");
//RIGHT     
ZipFile.CreateFromDirectory("C:\somefolder", "C:\someotherfolder\somefile.zip");

我曾经犯过同样的错误:将文件压缩到我正在压缩的同一文件夹中
这当然会导致错误。

关于c# ZipFile.CreateFromDirectory - 进程无法访问文件 "path_to_the_zip_file_created.zip",因为它正被另一个进程使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19395128/

相关文章:

c# - 扩展方法不等同于直接调用

.net - Visual Studio 在使用 .NET Framework 2.0 为 C++\CLI 窗体打开设计器时崩溃

.net - 无法从 Swift 访问 HttpPost Web Api

java - 将 Double 转换为 Int 时的不同答案 - Java 与 .Net

C# 从数据库列中获取所有电话号码并用逗号分隔并显示在文本框中

c# - 如何在单独的线程中正确关闭异步套接字监听器?

c# - 如何在 XNA 中播放动态声音?

c# - 为什么我不能在类上使用 ConditionalAttribute?

c# - Serilog 不登录到 .NET Core 2.1 中的控制台

c# - 例如,返回值从哪里来如果未填充到预期类型的​​已声明变量中,方法调用会继续吗?