Recently I needed to grab images via a URL for our project here at work. We basically have a web server the has tons of images for our various products in many different sizes and I wanted to be able to grab the images via a URL. I thought I would throw the code snippets up that are needed to do this.
The code to perform this is pretty straight forward. You basically need to create the URI object from the URL and them open up a new web request in order to pull the image.
You will notice that we catch and swallow both the IOExcpetion and the WebException. This is don't with intent <slapping hands> because if we cannot grab the image or it fails for any reason we want to return a null. This is a business requirement because when this happens we will display a 'place holder' image. Normally I would never advocate swalling excpetions, but sometimes you have to do what you have to do.
06-12-2007 8:27 AM