首页 > Web开发 > 详细

silverlight使用webclient下载uri,并转化为stream

时间:2015-10-01 16:29:16      阅读:252      评论:0      收藏:0      [点我收藏+]

  private void Button_Click_1(object sender, RoutedEventArgs e)

        {

// of the ASP.NET website.)
            string uri = Application.Current.Host.Source.AbsoluteUri;
            int index = uri.IndexOf("/ClientBin");
            uri = uri.Substring(0, index) + "/ProductList.bin";
            uri = uritxt.Text;
            // Begin the download.
            WebClient webClient = new WebClient();
            webClient.OpenReadCompleted += webClient_OpenReadCompleted;
            webClient.OpenReadAsync(new Uri(uri));
            webClient.DownloadProgressChanged += webClient_DownloadProgressChanged;

        }

        private void webClient_OpenReadCompleted(object sender,
 OpenReadCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                // (Add code to display error or degrade gracefully.)
            }
            else
            {
                Stream stream = e.Result;
                BinaryReader reader = new BinaryReader(stream);
                // (Now process the contents of the resource.)
                reader.Close();
            }
        }

        private void webClient_DownloadProgressChanged(object sender,
 DownloadProgressChangedEventArgs e)
        {
            lblProgress.Text = e.ProgressPercentage.ToString() + " % downloaded.";
            progressBar.Value = e.ProgressPercentage;
        }

 

silverlight使用webclient下载uri,并转化为stream

原文:http://www.cnblogs.com/xlyg-14/p/4851135.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!