I am looking for a "cheap" option to find out if a site exists, given a URL.

I have no control over the server environment, so I am not able to add web services or code to it.

Is there a way to find out whether a site exists on the specified URL without resorting to catching ClientRequestException?


So I know this is old, but Community decided we should look at it today...

You can enumerate the subwebs and put all the urls as keys in an object, then check if the url was put into the object or not...

var myCtx = SP.ClientContext.get_current();
var mySubWebs = myCtx.get_web().getSubwebsForCurrentUser();

myCtx.executeQueryAsync(function() {
    var subWebEnum = mySubWebs.getEnumerator(),
        webUrls = {},
    while (subWebEnum.moveNext()) {
        currWeb = subWebEnum.get_current();
        webUrls[currWeb.get_url()] = true;
    //following line for debugging in console
    window.subWebs = webUrls;
}, function(sender, args) {
    //failure handler

Then you can do things like subWebs['<absolute url>'] ? present : notPresent or if(subWebs['<absolute url>']) and make decisions based on that.

You do need to be on a page in the web where you are looking for subwebs in order for this to work.


I know these are not client object model related, but wouldn't these be quicker?

  1. Try pinging it? (if you get a response, there a good chance it exists).
  2. Use a http tool such as fiddler
  • I am looking for answers involving code... I know I can use WebRequest and see if I get a 404, but really interested in a "proper" SharePoint way of doing this. – Oded Jun 11 '12 at 13:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.