【发布时间】:2022-01-05 14:27:26
【问题描述】:
public HttpResponseMessage DownloadZipFile(List<FileModel> files)
{
HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK);
using (ZipFile zip = new ZipFile())
{
zip.AlternateEncodingUsage = ZipOption.AsNecessary;
zip.AddDirectoryByName("Files");
foreach (FileModel file in files)
{
if (file.IsSelected)
{
//byte[] buffer = new byte[4096];
byte[] fileBytes = System.IO.File.ReadAllBytes("files");
string s = Convert.ToBase64String(fileBytes);
zip.AddFile(file.FilePath, "Files");
}
}
}
}
错误详情
System.IO.FileNotFoundException HResult=0x80070002 Message=Could not find file 'C:\Program Files (x86)\IIS Express\files'. Source=<Cannot evaluate the exception source>
StackTrace: <Cannot evaluate the exception stack trace>
This exception was originally thrown at this call stack:
[External Code]
ZIpFile_Creation_API.Controllers.ZipAPIController.DownloadZipFile(System.Collections.Generic.List<ZIpFile_Creation_API.Models.FileModel>) in ZipAPIController.cs
[External Code]
【问题讨论】:
-
试试
zip.AddDirectoryByName(Server.MapPath("Files"));