基本代码:
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/