webclient 下载
Uri url = new Uri("http://localhost:2215/2.rar");WebClient client = new WebClient();client.OpenReadCompleted += new OpenReadCompletedEventHandler(client_OpenReadCompleted); client.OpenReadAsync(url);void client_OpenReadCompleted(object obj, OpenReadCompletedEventArgs e) { if (e.Error == null) { Stream stream = e.Result; byte[] by = new byte[stream.Length + 1]; stream.Read(by, 0, by.Length); FileStream fs = new FileStream("C:\\aa.rar", FileMode.CreateNew,FileAccess.Write); fs.Write(by, 0, by.Length); fs.Flush(); fs.Close(); } }