zoukankan      html  css  js  c++  java
  • silverlight使用webclient下载uri,并转化为stream

    
    

      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;
            }
  • 相关阅读:
    js 生成随机数
    解决微信浏览器无法使用reload()刷新页面
    js 去除左右空格
    小程序开发入门-第一天
    我的第一个JSP——动态web
    2019-3-6 复制粘贴
    2019-2-19 异常练习
    2019-1-19 object祖宗类的equals重写
    2019-1-15 课堂笔记
    2019-1-15 课后作业
  • 原文地址:https://www.cnblogs.com/xlyg-14/p/4851135.html
Copyright © 2011-2022 走看看