Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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
1  
Please work on your accept rate! This will motivate users to help you! For now, you accepted only once, your own answer. Also, I recommend you to mention, if you're working client-side or not, this will make answers much more accurate. –  Andrey Markeev May 2 '11 at 19:24

2 Answers 2

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

        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
share|improve this answer

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

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

share|improve this answer
1  
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

 
discard

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.