Cannot Convert System.String to System.Uri

dezkev picture dezkev · Sep 23, 2009 · Viewed 79k times · Source

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.

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

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

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

Things I have tried-

  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));  
    }
    

Answer

Digitalex picture Digitalex · Sep 23, 2009

This works just fine;

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

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".