gpt4 book ai didi

c# - 使用 C# 代码下载的 zip 文件无效

转载 作者:行者123 更新时间:2023-11-30 21:04:27 26 4
gpt4 key购买 nike

我有一个存储一些 zip 文件的 Dot Net MVC 服务器。如果单击超链接,我可以成功下载这些 zip 文件。但是,如果我尝试使用 WebClient 的 DownloadFile 下载 zip 文件,我可以下载 zip 文件,但出现错误“Windows 无法打开文件夹,压缩的 zip 文件夹无效”

服务器端代码:

public FilePathResult DownloadFile(int id)
{
string resultsdir = AppDomain.CurrentDomain.BaseDirectory + "Data\\ResultsDir\\" + res.RequestId.ToString();
string downloadFile = System.IO.Path.GetFileName(res.DownloadPath);
string zipPath = System.IO.Path.Combine(resultsdir, downloadFile);
return File(zipPath, "application/zip", downloadFile);
}

客户端我正在使用 Webclient 下载这个文件

WebClient wc = new WebClient();
wc.DownloadFile("http://servername/Results/DownloadFile/853", "localspkgfile.zip");

如果我通过单击浏览器上的超链接下载文件,文件大小为 2.9 MB。但是使用 webclient 文件大小为 5kb。看起来 WebClient 无法正确下载文件。任何人都可以建议我下载文件的方法。

最佳答案

我不知道你的代码有什么问题,但你正在下载的那个 5kb 文件几乎可以肯定是一个 HTML 错误页面,它可能包含信息,例如堆栈跟踪,这将帮助你找出问题所在.将其扩展名更改为 .html 并在浏览器中打开它。

关于c# - 使用 C# 代码下载的 zip 文件无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12351206/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com