關於下載路徑的隱藏都是通過傳遞一個數據庫中的ID,然後在另外一張頁面通過傳遞的ID在數據庫中讀出路徑。
c#中實現的方法(只需要.ASPX.CS的代碼就可以了)
string sel_sql="select FileVisualPath from TabMailAttachFiles where FileID=" Request.QueryString["destFileName"].ToString();
// string destFileName = Request.QueryString["destFileName"]!=null?Request.QueryString["destFileName"]:"";
string destFileName=ROA.Components.fune_commerce.Execad(sel_sql).Tables[0].Rows[0][0].ToString();
destFileName = Server.MapPath(".") destFileName;
destFileName = Server.UrlDecode(destFileName);
if(File.Exists(destFileName))
{
FileInfo fi = new FileInfo(destFileName);
Response.Clear();
Response.ClearHeaders();
Response.Buffer = false;
//Response.AppendHeader("Content-Disposition","attachment;filename=" HttpUtility.UrlEncode(Path.GetFileName(destFileName),System.Text.Encoding.Default));
Response.AppendHeader("Content-Disposition","attachment;filename=" HttpUtility.UrlEncode(Path.GetFileName(destFileName),System.Text.Encoding.UTF8));
Response.AppendHeader("Content-Length",fi.Length.ToString());
Response.ContentType="application/octet-stream";
Response.WriteFile(destFileName);
Response.Flush();
Response.End();
}
else
{
Response.Write("<script langauge=javascript>alert(文件不存在!);history.go(-1);</script>");
Response.End();
}