日期:2014-05-17  浏览次数:21215 次

如何用httpwebrequest实现多个文件的下载?
下面的代码用httpwebrequest实现了单个文件的下载:
               string savePath = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"DataBase\Image\test\" + PictureName//本地保存路径
                    , downFileUrl = "http://www.myserver.com/Image/" + PictureName;//下载文件的链接地址
                WebClient wcClient = new WebClient();
                WebRequest webReq = WebRequest.Create(downFileUrl);
                WebResponse webRes = webReq.GetResponse();
                int fileLength = int.Parse(webRes.ContentLength.ToString());

                Stream srm = webRes.GetResponseStream();
                StreamReader srmReader = new StreamReader(srm);
                byte[] bufferbyte = new byte[fileLength];
                int allByte = (int)bufferbyte.Length;
                int startByte = 0;
                while (fileLength > 0)
                {
                    //Application.DoEvents();
                    int downByte = srm.Read(bufferbyte, startByte, allByte);
                    if (downByte == 0) { break; };
                    startByte += downByte;
                    allByte -= downByte;
                }

                if (!File.Exists(savePath))
                {
                    string[] dirArray = savePath.Split('\\');
                    string temp = string.Empty;
                    for (int i = 0; i <&n