Let's say we are receiving the uriString as a parameter and we want to assign that string URI to an image control's source property. What we need to use is the Uri.IsWellFormedUriString(string uriString, UriKind uriKind) which will check that the URI is well formed and that it doesn't required further scaping:
public void SetImageSource(String uriString)
{
if (Uri.IsWellFormedUriString(uriString, UriKind.Absolute))
{
this.Thumbnail.Source = new BitmapImage(new Uri(uriString));
}
}
Then you can use the "else" block to set the thubmnail image of our control to a default well formed URI.
Hope it is useful for you.
Cheers!
-arbbot
Thanks. The Uri class can be our friend once again. I've been using the Uri class - but must have not noticed this method for validation.
ReplyDeleteThanks!
Thanks..I have googled on various sites but I like your post the most. It is simple and to the point.
ReplyDelete