2

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.

0

2 Answers 2

2

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...
            }
        }

        clientContext.ExecuteQuery();

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
0

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

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsite.exists.aspx

2
  • 1
    does this work if I am working through the Sharepoint Client interface? Commented May 2, 2011 at 20:38
  • Does not work in client object model Commented Aug 13, 2013 at 13:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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