string strFilePhysicalPath = Server.MapPath("~/" + strFileUploadPath + strFileName);
        Response.Clear();
        Response.ContentType = "application/octet-stream";
        Response.AddHeader("Content-Disposition", "attachment;FileName=" + HttpUtility.UrlEncode(strFileName, System.Text.Encoding.UTF8));
        Response.WriteFile(strFilePhysicalPath);
        Response.End();点击下载按钮后,会弹出对话框,但问题来了,用迅雷下的话,下的就是页面了,而不是文件
必须点另存为,使用IE本身的才行,有什么解决办法吗?还有我以前看到过这个效果,就是IE最顶短弹出个控件,点击那上面下载文件,而且迅雷不会自动弹出来

解决方案 »

  1.   

            public static bool Start(string fullPath, bool deleteSource)
            {
                try
                {
                    FileInfo fi = new FileInfo(fullPath);
                    string fileName = fi.Name;
                    
                    HttpResponse rpse = HttpContext.Current.Response;
                    rpse.ContentType = "application/octet-stream";
                    rpse.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName, Encoding.UTF8));                using (FileStream fs = File.OpenRead(fullPath))
                    {
                        long fLen = fs.Length;
                        int size = 102400;//每100K同时下载数据 
                        byte[] readData = new byte[size];//指定缓冲区的大小 
                        if (size > fLen) size = Convert.ToInt32(fLen);
                        long fPos = 0;
                        bool isEnd = false;
                        while (!isEnd)
                        {
                            if ((fPos + size) > fLen)
                            {
                                size = Convert.ToInt32(fLen - fPos);
                                readData = new byte[size];
                                isEnd = true;
                            }
                            fs.Read(readData, 0, size);//读入一个压缩块 
                            rpse.BinaryWrite(readData);
                            fPos += size;
                        }
                    }
                    if (deleteSource) File.Delete(fullPath);
                    return true;
                }
                catch
                {
                    return false;
                }
            }
    //fullPath 完整的路径, deleteSource 是否下载后删除源文件
      

  2.   

    我又想起个问题,以前玩静态页面的时候能下载成功,而且也能用迅雷,
    发现是这样了的 ASP.NET点下载按钮后地址都是不会变的,但静态页面是把那个文件的地址放在页面上了,做成了个超级连接
    例如:ftp://210.51.10.115/2006mf/ITAT/caozuo/javascript/jav0101.exe
    所以能下载下来,但现在地址还是那个页面地址,所以下的是页面
      

  3.   

    一个response 输出,一个是把文件的地址放那等你下载,原理不同........