Download image stream using WebClient class.

Beantwortet Download image stream using WebClient class.

  • Tuesday, May 08, 2012 3:18 AM
     
     

    Hi,

    I have a list of URLs which points me to some images (JPGs).

    For every URL from the list, I would like to use image's stream.

    I used WebClient class in order do that but it seems like now, it doesn't work anymore, and I'm pretty sure is due to the fact that the clientaccesspolicy.xml (I get a SecurityException) file is missing from the target server (don't know why it worked in the first place).

    1.Is there any way to bypass the clientaccesspolicy.xml? 

    2.If not (I'm pretty sure this is the answer), is anything I can do, on my side, in order to make this working?

    3.Is there any other way to take the stream of those images using the URL list?

    My code:

    // FOREACH LOOP

    WebClient webClient = new WebClient();
    webClient.OpenReadCompleted += (s, ev) =>
    {
        if (ev.Error != null)
        {
             // handle the error response
        }
        else
        {
            // handle the ev.Result (which is a Stream)
         }
    };
            
    webClient.OpenReadAsync(new Uri(url)));

    // END FOREACH LOOP

All Replies