silverlight使用webclient下载uri,并转化为stream
2015-10-01 16:08
302 查看
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; }
相关文章推荐
- zw版【转发·台湾nvp系列Delphi例程】HALCON TestRegionPoint2
- 12 个免费学习编程的好地方
- Java中的异常处理机制的简单原理和应用
- web前端,jquery实现瀑布流总结6,jQuery 事件 - scroll() 方法 滚动
- 2014百度之星资格赛的第二个问题
- zw版【转发·台湾nvp系列Delphi例程】HALCON TestRegionPoint1
- [Android基础]文件读写操作
- iOS 之 (闭包)block传值
- zw版【转发·台湾nvp系列Delphi例程】HALCON BitXor
- web前端,jquery实现瀑布流总结5,jQuery CSS 操作 - css() 方法
- Linux 在下面MATLAB下载
- Java模拟简易ATM机运行(无界面、无数据库)
- codeforces 580 E. Kefa and Watch (字符串hash + 线段树)
- web前端,jquery实现瀑布流总结4,数组
- SCU 4438 Censor(KMP / HASH)
- 美团+百度+网易+去哪儿+58面试总结
- web前端,jquery实现瀑布流总结3,Math.floor()对数进行下舍入
- 如何实现背景透明,文字不透明,兼容所有浏览器?
- 中间固定两侧自适应三栏布局
- web前端,jquery实现瀑布流总结2,each遍历