using var zipArchive = ZipFileOpenzipPath ZipArchiveModeCreate foreach var item in list string physicalPath = PathCombine_pathConfigUpload
此错误表示正在尝试访问另一个进程正在使用的文件。在这种情况下,可能是因为您正在尝试创建一个已存在的压缩文件。
您的代码中有一个问题,即在使用zipArchive.CreateEntryFromFile(zipPath, physicalPath);时,将zipPath作为参数传递给了CreateEntryFromFile方法。这是不正确的,应该将physicalPath作为参数传递。
修正后的代码如下:
using (var zipArchive = ZipFile.Open(zipPath, ZipArchiveMode.Create))
{
foreach (var item in list)
{
string physicalPath = Path.Combine(_pathConfig.UploadPath, "Admin", "OSS", "Open", item.ResPath);
if (System.IO.File.Exists(physicalPath))
zipArchive.CreateEntryFromFile(physicalPath, item.ResPath);
}
}
请确保zipPath参数指定一个不存在的文件路径,以防止覆盖现有文件
原文地址: https://www.cveoy.top/t/topic/iN2t 著作权归作者所有。请勿转载和采集!