文件全部存储在服务器上,如何实现多个文件下载
现在代码如下
protected void Page_Load(object sender, EventArgs e)
{
string[] arr = { "alert.png", "info.png", "valid.png" };
for (int i = 0; i < arr.Length; i++)
{
try
{
string filePath = Server.MapPath("/images/"+arr[i]);
//以字符流的形式下载文件
FileStream fs = new FileStream(filePath, FileMode.Open);
byte[] bytes = new byte[(int)fs.Length];
fs.Read(bytes, 0, bytes.Length);
fs.Close();
Response.ContentType = "application/octet-stream";
//通知浏览器下载文件而不是打开
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode("测试"+arr[i], System.Text.Encoding.UTF8));
Response.BinaryWrite(bytes);
Response.Flush();
}
catch { }
}
Response.End();
}