asd*_*asd 2 c# asp.net zip download response.transmitfile
我正在使用c#.net应用程序,我需要使用c#codebase下载一个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();
Run Code Online (Sandbox Code Playgroud)
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();
Run Code Online (Sandbox Code Playgroud)