UC_UpDown.xaml.cs
- using System; using System.Collections.Generic;
- using System.Linq; using System.Net;
- using System.Windows; using System.Windows.Controls;
- using System.Windows.Documents; using System.Windows.Input;
- using System.Windows.Media; using System.Windows.Media.Animation;
- using System.Windows.Shapes;
- using System.Windows.Media.Imaging; //因为要使用BitmapImage using System.IO; //因为要使用Stream
- namespace HCLoad
- { public partial class UC_UpDown : UserControl
- { //1、WebClient 对象一次只能启动一个请求。如果在一个请求完成(包括出错和取消)前,即IsBusy为true时,进行第二个请求,则第二个请求将会抛出 NotSupportedException 类型的异常
- //2、如果 WebClient 对象的 BaseAddress 属性不为空,则 BaseAddress 与 URI(相对地址) 组合在一起构成绝对 URI //3、WebClient 类的 AllowReadStreamBuffering 属性:是否对从 Internet 资源接收的数据做缓冲处理。默认值为true,将数据缓存在客户端内存中,以便随时被应用程序读取
- //获取选定图片信息
- System.IO.FileInfo fileinfo; public UC_UpDown()
- { InitializeComponent();
- } #region 下载图片
- private void btnDownload_Click(object sender, RoutedEventArgs e) {
- //向指定的Url发送下载流数据请求 String imgUrl = "http://www.easck.com//OpenReadCompletedEventArgs.Error - 该异步操作期间是否发生了错误 //OpenReadCompletedEventArgs.Cancelled - 该异步操作是否已被取消
- //OpenReadCompletedEventArgs.Result - 下载后的 Stream 类型的数据 //OpenReadCompletedEventArgs.UserState - 用户标识
- if (e.Error != null)
- { MessageBox.Show(e.Error.ToString());
- return; }
- if (e.Cancelled != true) {
- //获取下载的流数据(在此处是图片数据)并显示在图片控件中 //Stream stream = e.Result;










