SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I run a (CAML based query) executeQuery against Sharepoint, sometimes the site does not exist (it is created by a workflow process which may not have run). When this happens, I get a ClientRequestException:

Cannot contact site at the specified URL http:/[mypath]. There is no Web named "/[mypath]/_vti_bin/sites.asmx".

Is there a check I can run? I think it's probably preferable to do a bool check than to wrap with a try catch.

This code runs client side, so I believe there is a different set of APIs available.

share|improve this question
up vote 2 down vote accepted

I think, the solution here is to use the scopes approach.

There are two scope types in SharePoint: ConditionalScope and ExceptionHandlingScope. They allow you to implement conditional behaivour server-side. Only one request is sent to the server. Logics in scopes are packed together and sent to the server which is executed as a whole in a single request.

The easest way here is to implement server-side try-catch behaivour, using ExceptionHandlingScope, for example:

        ClientContext clientContext = new ClientContext("http://localhost");

        ExceptionHandlingScope scope = new ExceptionHandlingScope(clientContext);

        using (scope.StartScope())
            using (scope.StartTry())
                // do your actions here

            using (scope.StartCatch())
                // if error is occured...


As far as I know, there are no analogues for SPWeb.Exists in client object model, so using ExceptionHandlingScope is probably the best solution here.

Some articles, which can help to understand server-scopes idea:

  1. How to: Use Conditional Scope
  2. How to: Use ExceptionHandlingScope
share|improve this answer

If you are writing code always use this boolean check: SPSite.Exists()

share|improve this answer
does this work if I am working through the Sharepoint Client interface? – MedicineMan May 2 '11 at 20:38
Does not work in client object model – Steffen Schindler Aug 13 '13 at 13:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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