tags:

views:

425

answers:

1

I want to check if a URI returns a valid result. Example:

String path = String.Format("{0}/agreements/{1}.gif", PicRoot, languageTwoLetterCode);
WebRequest request = WebRequest.Create(new Uri(path, UriKind.Relative));
...

This throws a notsuportedexception. So I figure I should be providing the absolute URI. All examples I can find use a hardcoded root (like www.example.com). This is off course unacceptable because it is uncertain what the actual root of the website will be.

How can I either check the result from a relative URI or find the current root? Are there better ways to check if say "/content/pics/agreements/en.gif" returns a gif or a 404?

+1  A: 

You can get the root of the web site from the server object.

You could use Server.MapPath (see also) and then check if the physical path is on the server (use File.Exists)

Ian Ringrose