//事件
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;
}
}