当前位置:编程学习 > C#/ASP.NET >>

C#实现隐藏文件下载路径的方法介绍

关于下载路径的隐藏都是通过传递一个数据库中的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();
   }

补充:软件开发 , C# ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,