【问题标题】:System.IO.FileNotFoundException: 'Could not find file 'C:\Program Files (x86)\IIS Express\files'.'System.IO.FileNotFoundException: '找不到文件'C:\Program Files (x86)\IIS Express\files'。
【发布时间】: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"));

标签: c# asp.net exception


【解决方案1】:

至少需要一些列表参数。

在阅读之前建议 File.Exists(filePath)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-12
    • 2016-12-19
    • 1970-01-01
    相关资源
    最近更新 更多