下载文件Asp.Net

时间:2015-10-12 12:07:08

标签: c# asp.net

我在文件系统中有.zip个文件。我想下载该文件。到目前为止我已经完成了

HttpContext.Current.Response.ContentType = "application/zip";
            HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment; filename=" + FileName);
            HttpContext.Current.Response.TransmitFile(zipName);
            HttpContext.Current.Response.End();

但它直接打开文件而不是保存它。如果保存,如何下载呢?

我也见过DownloadFile(String, String),但在我的案例中,第一个论点是什么?

2 个答案:

答案 0 :(得分:1)

你必须压缩并从该zip获取字节并传递它们

context.Response.AppendHeader("Content-Disposition", string.Format("attachment; filename={0}.{1}", fileName, fileExtension));
context.Response.ContentType = "application/octet-stream";
context.Response.OutputStream.Write(zipBytesArray, 0, zipBytesArray.Length);
context.Response.End();

答案 1 :(得分:0)

如果您想从远程服务器下载它,那么您只需使用WebClient类

即可
ra1

ra2