日期:2014-05-17 浏览次数:20621 次
string Name;
string Path;
protected void Button2_Click(object sender, EventArgs e)
{
foreach (Control control in Panel1.Controls)
{
try
{
if (((CheckBox)control).Checked)
{
//获取选择文件的相对路径。我将文件的相对路径写在了CssClass里面
Path = ((CheckBox)control).CssClass;
string[] path = Path.Split('/');
Name = path[path.Length - 1];
download(Path, Name);
}
}
catch (Exception)
{ continue; }
}
}
private void download(string Path, string Name)
{
//用户下载文件时保存文件使用的默认命名
string downLoadFileName = Name;
//设定响应类型为下载
this.Response.ContentType = "application/x-zip-compressed";
//获取下载文件在服务器端的物理路径
string downLoadPath = this.Server.MapPath(Path);
//添加响应头标示信息 this.Server.UrlPathEncode对下载文件名进行编码 防止文件名乱码
this.Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", this.Server.UrlPathEncode(downLoadFileName)));
//下载文件输出
this.Response.TransmitFile(downLoadPath);
this.Response.End();
}