要做一个文件的下载,我自己做了上传文件,把文件上传到了upfile文件夹里面.
  现在打算在页面上下载这个文件夹的文件,并且这个文件夹里面的所有文件绑定到页面上提供下载,怎么做啊各位大哥,我都快急死了做了几次都不行.有会的给我说说. 有实例的可以发我邮箱 [email protected]

解决方案 »

  1.   

    如果对下载工具没有什么要求的话
    你直接用<a>标签就可以了
    这样写<a herf="文件地址">文件名</a>
      直接点击就可以下载 动态绑定道理也是一样,把地址绑定到href就行了
      

  2.   

    /// <summary>
        /// 从服务器中下载文件
        /// </summary>
        /// <param name="path">文件路径</param>
        /// <returns></returns>
        public void DownFile(string FileName)
        {
            string path = Server.MapPath("~/" + FileName);
            string SaveFileName = path.Substring(path.LastIndexOf("\\") + 1);
            FileStream myFile = File.OpenRead(path);
            byte[] fileCont = new byte[myFile.Length];
            myFile.Read(fileCont, 0, (int)myFile.Length);
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(DateTime.Now.ToString("yyyyMMdd") + SaveFileName, System.Text.Encoding.UTF8));
            HttpContext.Current.Response.AddHeader("Content-Length", myFile.Length.ToString());
            //HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
            HttpContext.Current.Response.BinaryWrite(fileCont);
        }
    这是下载单个文件的,供参考
      

  3.   

    这有个完整的例子
      http://blog.csdn.net/pgameli/archive/2009/03/16/3994438.aspx
      

  4.   

    public void Download(string download_path)
            {
            //string filepath = HttpContext.Current.Server.MapPath(download_path);
            string filepath = download_path;
            FileStream filestream = new FileStream(filepath, FileMode.Open, FileAccess.Read, FileShare.Read);
            long filesize = filestream.Length;
            //让客户端浏览器正确识别这个文件的类型和文件大小 
            string filename = Path.GetFileName(filepath).ToLower();
            HttpContext.Current.Response.ContentType = "application/octet-stream";
            HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=\"" + HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8) + "\";");
            HttpContext.Current.Response.AddHeader("Content-Length", filesize.ToString());
            //将文件中的数据发送到客户端 
            byte[] filebuffer = new byte[filesize];
            filestream.Read(filebuffer, 0, (int)filesize);
            HttpContext.Current.Response.BinaryWrite(filebuffer);        filestream.Close();
            HttpContext.Current.Response.End(); 
            }
      

  5.   

    参考:http://www.cnblogs.com/insus/articles/1411761.html