无法将System.String转换为System.Uri [英] Cannot Convert System.String to System.Uri

查看:249
本文介绍了无法将System.String转换为System.Uri的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Web客户端类从Internet(实际上是Flickr)下载文件. 只要我使用WebClient().DownloadData(string),它就可以正常工作,但是由于它不是异步的,因此会锁定UI.

I am using the Web Client Class to download files from the internet (Flickr actually). This works fine as long as I use : WebClient().DownloadData(string) , however this locks up the UI as it is Not asynchronous.

但是,当我尝试WebClient().DownloadDatAsync(string)时,出现编译错误: 无法将System.String转换为System.Uri".

However when I try WebClient().DownloadDatAsync(string), I get a compile error: "Unable to convert System.String to System.Uri".

字符串MediumUrl返回"http://farm4.static.flickr.com/2232/2232/someimage.jpg"

The string MediumUrl returns "http://farm4.static.flickr.com/2232/2232/someimage.jpg"

所以问题是如何将字符串"http://farm4.static.flickr.com/2232/2232/someimage.jpg"转换为Uri.

So the question is how do I convert the string "http://farm4.static.flickr.com/2232/2232/someimage.jpg" to a Uri.

我尝试过的事情-

  1. 我试图将其投放到Uri,但这也不起作用.
  2. 我已经尝试过Uri myuri = new uri(string)-如上所述错误.

  1. I have tried to cast it to Uri but that does not work either.
  2. I have tried Uri myuri = new uri(string) - errors out as above.

foreach (Photo photo in allphotos)  
{  
    //Console.WriteLine(String.Format("photo title is :{0}", photo.Title));
    objimage = new MemoryStream(wc.DownloadData(photo.MediumUrl));
    images.Add(new Pictures(new Bitmap(objimage), photo.MediumUrl, photo.Title));  
}

推荐答案

这很好;

System.Uri uri = new System.Uri("http://farm4.static.flickr.com/2232/2232/someimage.jpg");

顺便说一句;我注意到您用小写的uri输入了新uri(...)的输入错误.这不是您的问题,因为它应该是"new Uri".

By the way; I notice you mistyped the expression new uri(..., with lowercase uri. This is not your problem, is it? Because it should be "new Uri".

这篇关于无法将System.String转换为System.Uri的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆