页面上有个按钮A,点击A生成一个压缩包并要将这个压缩包下载下来。
生成压缩包的功能已实现,现在要实现同时下载的功能,我的初步想法是在
页面上放一个超链接,生成压缩包的同时生成超链接,但是大家都知道超链接
是需要点击才能实现下载的,我要实现的就是不用点击超链接,在点按钮A生成压缩包的
同时将生成的压缩包下载下来?

解决方案 »

  1.   


             Response.Clear();
    Response.ClearHeaders();
    Response.Buffer = false;
    Response.ContentType = "application/octet-stream";

    Response.ContentEncoding = System.Text.Encoding.Default;
    Response.AddHeader("Content-Disposition", "attachment;filename="+HttpUtility.UrlEncode(fileName)) ;

    Response.WriteFile(fullName,0,length);
    Response.Flush();
      

  2.   

    fileName,fullName,length各是什么呢?
      

  3.   

    fileName、fullName、length是什么啊?
      

  4.   

          Response.Clear(); 
      
    Response.ContentType = "application/octet-stream";
    Response.AddHeader("Content-Disposition", "attachment;FileName="+YourFileName);
    Response.BinaryWrite((byte[])YourFileData.Rows[0]["AttachmentContent"]);
    Response.End();
      

  5.   

    FileName要下载的文件名称FullName文件的全称length下载对应的文件大小
      

  6.   

    http://blog.csdn.net/xiandawang/archive/2007/05/22/1620208.aspx 这里有关下载的详细代码,楼主可以参考
      

  7.   

     /// <summary>
        /// 文件下载
        /// </summary>
        /// <param name="FileName">要下载的文件名称</param>
        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("yyyyMMddhhmmss") + 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);
        
        }
      

  8.   

    顺便请楼主将生成压缩包的代码发我看看,谢了
    我的qq为121067015    [email protected]
      

  9.   

    我要下载的文件的全称为~/UpLoad/3.zip,要下载的文件的名称为3.zip,文件的大小为400kb
    我的代码是这样子写的
     wName = Zip;
                        [align=left]WorkName = string.Format("<a href='{0}'>{1}</a>", Zip, Zip.Substring(Zip.LastIndexOf('/') + 1));                    Response.Clear();
                        Response.ClearHeaders();
                        Response.Buffer = false;
                        Response.ContentType = "application/octet-stream";                    Response.ContentEncoding = System.Text.Encoding.Default;
                        Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(Zip.Substring(Zip.LastIndexOf('/') + 1)));                    Response.WriteFile(Zip, 0, 52428800);
                        Response.Flush(); [/align]下载下来打开提示压缩文件格式未知或数据已损坏
      

  10.   

    FileStream fs = new FileStream(Server.MapPath("/UpLoad/3.zip"),FileMode.Open);
    long fsize = fs.Length;

    Response.ContentType = "application/octet-stream";
    Response.AddHeader("Content-Disposition","attachment; filename='" + HttpUtility.UrlEncode("3.zip",System.Text.Encoding.UTF8) + "'"); 
    Response.AddHeader("Content-Length",fsize.ToString());  byte[] fileBuffer = new byte[fsize];
    fs.Read(fileBuffer, 0, (int)fsize);
    fs.Close();
    Response.BinaryWrite(fileBuffer); 
    Response.End();
      

  11.   

    假设生成的文件是 a.rar ,地址是 hrefPath,生成结束后加句话就是了 string fileName="a.rar";
     Response.Redirect(hrefPath+fileName);