c#ZipFile.CreateFromDirectory-进程无法访问文件“ path_to_the_zip_file_created.zip”;因为它正在被另一个进程使用 [英] c# ZipFile.CreateFromDirectory - the process cannot access the file "path_to_the_zip_file_created.zip" because it is being used by another process
问题描述
基本代码:
string startPath = @"C:\intel\logs";
string zipPath = @"C:\intel\logs-" + DateTime.Now.ToString("yyyy_dd_M-HH_mm_ss") + ".zip";
ZipFile.CreateFromDirectory(startPath, zipPath);
错误:该进程无法访问文件 path_to_the_zip_file_created.zip,因为
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上运行时出现错误消息。
The above setup works fine on windows 7 where I have Visual Studio installed but I get the above error message when running on Windows Server 2008R2.
我已经检查了防病毒日志,它不会阻止应用程序,也不会锁定创建的zip文件。 / p>
I have checked the antivirus logs and it does not block the application, nor does it lock the zip file that is created.
推荐答案
//WRONG
ZipFile.CreateFromDirectory("C:\somefolder", "C:\somefolder\somefile.zip");
//RIGHT
ZipFile.CreateFromDirectory("C:\somefolder", "C:\someotherfolder\somefile.zip");
我经常执行相同的错误:将文件压缩到与我相同的文件夹中m zip 。
当然会导致错误。
I use to do the same error: zipping a file into the same folder that I'm zipping.
This causes an error, of course.
这篇关于c#ZipFile.CreateFromDirectory-进程无法访问文件“ path_to_the_zip_file_created.zip”;因为它正在被另一个进程使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!