gpt4 book ai didi

c# - 如何从 C# 代码传输 zip 文件

转载 作者:行者123 更新时间:2023-12-03 03:08:19 25 4
gpt4 key购买 nike

我正在使用 c#.net 应用程序,其中需要使用 c# 代码库下载 zip 文件。我使用以下代码下载文件:

Response.ContentType = "application/zip"                       
Response.AppendHeader("Content-Disposition", string.Format("attachment; filename = {0}", System.IO.Path.GetFileName(sZipFileName)));
Response.TransmitFile(sZipFilePath);
HttpContext.Current.ApplicationInstance.CompleteRequest();

zip 文件已传输,但当我下载后尝试打开 zip 文件时,收到错误消息“无法打开文件:该文件看起来不是有效的存档”

请让我知道我哪里做错了,以及如何获取 zip 文件并将其解压而不会出现任何错误。

提前致谢

最佳答案

我不确定为什么你的代码片段不起作用,但这里有一些我用来在我的应用程序中执行相同操作的代码。希望对您有所帮助。

var updateFile = new FileInfo("path/to/file");
Response.ContentType = "application/octet-stream";
Response.AddHeader("content-disposition", "attachment;filename=\"" + Path.GetFileName(updateFile.FullName) + "\"");
Response.AddHeader("content-length", updateFile.Length.ToString());
Response.TransmitFile(updateFile.FullName);
Response.Flush();

关于c# - 如何从 C# 代码传输 zip 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4898526/

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