<a href="down.aspx?id=324">下载文件</a>点击这个连接后会打开down.aspx文件,通过后台程序找到要下载的文件(已解决)后弹出下载对话框,同时关掉down.aspx文件,只剩下下载对话框例如BTBBT的种子下载
http://bbs.btbbt.com/attachpage.php?aid=530070

解决方案 »

  1.   

    set :conenttype = application/octet-stream
      

  2.   

    string pathfile = @"D:\需求说明书1.doc";//需要下载的文件
            FileStream fs = new FileStream(pathfile, FileMode.Open, FileAccess.Read);
            long p = 0;
            FileInfo fi = new FileInfo(pathfile);
            long l = fi.Length;
            if (Request.Headers["Range"] != null)
            {
                Response.StatusCode = 206;
                p = long.Parse(Request.Headers["Range"].Replace("bytes=", "").Replace("-", ""));
            }        Response.AddHeader("Content-Length", ((long)(l - p)).ToString());
            if (p != 0)
            {
                Response.AddHeader("Content-Range", "bytes " + p.ToString() + "-" + ((long)(l - p)).ToString() + "/" + l.ToString());
            }        Response.ContentType = "application/octet-stream";
            Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(pathfile));
            fs.Position = p;        int i = 1;
            byte[] b = new Byte[1024];
            while (i > 0)
            {
                i = fs.Read(b, 0, b.Length);
                Response.OutputStream.Write(b, 0, i);
            }        fs.Close();
            Response.End();
      

  3.   

    Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(pathfile));--> Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fi.Name));
      

  4.   

    xiaotupansy(分基本靠接)成功下载,不过下载对话框上的吧服务端文件物理路径也写出来了。能在隐藏吗?
      

  5.   

    xiaotupansy(分基本靠接)按你下面的说明可以实现了,但是和bt之家那个还是有点不一样。需要点保存的时候down.aspx才能关闭,不能电完连接就关闭吗?在一个,这段代码支持任意文件格式和大小吗?
      

  6.   

    xiaotupansy(分基本靠接)
    上一个问题也已经解决,
    怎么解决中文乱码问题???
      

  7.   

    HttpUtility.UrlEncode(fi.Name))
    这一行就是用来解决中文乱码的啊,这是我知道的最简单的代码了