客户端一次可上传多个文件,路径存储的数据库里,求在客户端如何实现下载多个文件。string[] strPathList = strPath.Split(';');
                int m = 0;
                for (int i = 0; i < strPathList.Length; i++)
                {
                    string filePath = "~" + strPathList[i].Remove(0, 2);
                    if (File.Exists(Server.MapPath(filePath)))
                    {
                        m++;
                        string fileName = Upload.getUpFileName(filePath, "//");
                        bufferName.Append("<a id='file"+ i.ToString() + "' runat='server' href='" + strPathList[i] + "' target='_blank' >" + m +"、"+fileName + "</a>");
                        bufferName.Append("<br />");
                    }
                }
                Div1.InnerHtml = bufferName.ToString();这里只是实现的超链接下载,有好的方法吗(真正的下载 DownLoadFile)?

解决方案 »

  1.   

    public static void FileDownload(string FileName)
    {
    String FullFileName = System.Web.HttpContext.Current.Server.MapPath(FileName);
    FileInfo DownloadFile = new FileInfo(FullFileName);
    System.Web.HttpContext.Current.Response.Clear();
    System.Web.HttpContext.Current.Response.ClearHeaders();
    System.Web.HttpContext.Current.Response.Buffer = false;
    System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream";
    System.Web.HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(DownloadFile.FullName, System.Text.Encoding.UTF8));
    System.Web.HttpContext.Current.Response.AppendHeader("Content-Length", DownloadFile.Length.ToString());
    System.Web.HttpContext.Current.Response.WriteFile(DownloadFile.FullName);
    System.Web.HttpContext.Current.Response.Flush();
    System.Web.HttpContext.Current.Response.End();
      

  2.   


    你理解错了,客户端相关的文件,点击下载,而文件控件是动态生成的,所以好像不可能调用FileDownload来下载文件。
      

  3.   

     if (dr.Read())
            {
                string fname1 = dr["m_name"].ToString();
                string DownloadFileName = "~/upfile/" + fname1;
                string filepath = Server.MapPath(DownloadFileName);
                string filename = Path.GetFileName(filepath);
                FileInfo file = new FileInfo(filepath);
                Response.Clear();
                Response.ContentType = "application/octet-stream";
                Response.AddHeader("Content-Disposition", "attachment;     filename=" + HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8));
                Response.AddHeader("Content-length", file.Length.ToString());
                Response.Flush();
                Response.WriteFile(filepath);