您的位置:首页 > 其它

web页面中点击下载跳出保存、打开窗体

2009-12-24 15:56 330 查看
//事件

filepath = Request.PhysicalApplicationPath + @"Up_Load/SaveFile";
cFile(GridView1.Rows[e.RowIndex].Cells[2].Text.ToString());

//封装方法

private void cFile( string carg)
{
FileLoad(this.CurrentDirectory, carg);
}

public void FileLoad(string filepath, string argStr)
{
string filename = Path.Combine(filepath, argStr);
//设置返回类型
System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream";

//对文件名做标准编码
string Encodefilename = System.Web.HttpContext.Current.Server.UrlEncode(argStr);
Encodefilename = Encodefilename.Replace('+', ' ');

//下载文件提示
System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + Encodefilename);

System.Web.HttpContext.Current.Response.TransmitFile(filename);
System.Web.HttpContext.Current.Response.End();

}

string filepath = "";
string CurrentDirectory
{
get
{
string Vfilepath = this.ViewState["CurrentDirectory"] as string;
if (string.IsNullOrEmpty(Vfilepath))
{
Vfilepath = this.filepath + @"/" + depart + @"/";
}
return Vfilepath;
}
set
{
this.ViewState["CurrentDirectory"] = value;
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐