string pathfile = 文件的物理路径;
        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=" + fi.Name);
        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();
还有一个小问题,这个东东下下来的东西的名字是乱码,怎么才能让他变正常啊?

解决方案 »

  1.   

    对IE配置,设置成总以UTF-8发送IE---Internet选项----高级,到最后一个,选中就可以了试试
      

  2.   

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

  3.   

    Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fi.Name));
    这个东西怎么昨天不行,今天就可以了?真是奇怪
    昨天是一堆数字和字符的组合.
      

  4.   

    Response.AddHeader("Content-Disposition", "attachment; filename=" +HttpUtility.UrlEncode(thefile.Name,System.Text.Encoding.UTF8));