问题描述:页面A实现了 文件上传功能(word excel 两种格式,文件保存在数据库中)。页面B把文件显示出来,点击文件名字,弹出对话框,“打开” “下载” “取消”。有点像邮箱里面 的附件那样,点一下 就弹出一个对话框。假设 页面A 已经搞定了。现在需要做页面B 请问如何实现啊 ??

解决方案 »

  1.   

    很简单,将你要链接的地址引入到同一个页面a.rarb.rar 这都引入到一个页面download.aspx?id=XX  其中id根据你传入的编号做标识出是下载a,不审b再在download.aspx页面写下面一段代码即可    //下载
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request["ID"] != null)
            {
                System.IO.FileInfo file = new System.IO.FileInfo(Request["url"].ToString());            Response.Clear();
                Response.ClearHeaders();
                Response.Buffer = false;
                Response.Charset = "GB2312";
                Response.ContentEncoding = System.Text.Encoding.UTF8;
                Response.AddHeader("Content-Disposition", "attachment;  filename=\"" + Server.UrlEncode(file.Name) + "\"");
                Response.AddHeader("Content-Length", file.Length.ToString());
                //Response.ContentType = "application/octet-stream";
                Response.ContentType = "application/x-zip-compressed";
                //Response.WriteFile(file.FullName);
                Response.TransmitFile(file.FullName);
                if (Request["id"] != null)
                {
                    downloadcount();
                }
                Response.End();
            }    }
      

  2.   

    sdr.IsDBNull(1)
    用于判断指定列是否为null
      

  3.   

    downloadcount(); 
    哪里来的?这个方法你没有用的,这个方法是做计数用的,指下载的次数
      

  4.   

    各位高手 能给这段函数 加一下注释么? 我想知道怎么用哦,我是c#新手,连个菜鸟都不算啊 哈哈 。谢谢啦!!!!
    只要告诉我  如何 获取 文件名 文件路径, 以及在前台页面使用什么空间 把文件名显示出来就可以了 哦 。//下载
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request["ID"] != null)
            {
                System.IO.FileInfo file = new System.IO.FileInfo(Request["url"].ToString());            Response.Clear();
                Response.ClearHeaders();
                Response.Buffer = false;
                Response.Charset = "GB2312";
                Response.ContentEncoding = System.Text.Encoding.UTF8;
                Response.AddHeader("Content-Disposition", "attachment;  filename=\"" + Server.UrlEncode(file.Name) + "\"");
                Response.AddHeader("Content-Length", file.Length.ToString());
                //Response.ContentType = "application/octet-stream";
                Response.ContentType = "application/x-zip-compressed";
                //Response.WriteFile(file.FullName);
                Response.TransmitFile(file.FullName);
                if (Request["id"] != null)
                {
                    downloadcount();
                }
                Response.End();
            }    }