我做一个上传控件和数据库连接的系统。
我把上传文件的绝对地址放在数据库里,现在想在gridview里下载上传的文件。
在模板编辑模式里,我把存放绝对地址那一列的textbox控件换成了hyperlink控件,
并绑定到数据库。显示结果只是绝对地址。
求助,请达人帮忙

解决方案 »

  1.   

    protected void DownLoadFile(string path)
            {                try
                    {
                        FileInfo file = new FileInfo(path);
                        Response.Clear();
                        Response.AddHeader("Content-Length", file.Length.ToString());
                        Response.Charset = "GB2312";
                        Response.ContentEncoding = Encoding.UTF8;
                        Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(file.Name));
                        Response.ContentType = "application/octet-stream";
                        Response.WriteFile(file.FullName);
                        Response.Flush();
                        Response.Close();
                    }
                    catch (Exception err)
                    {                }
            }