I have written a code relying on Managed Client Object Model which performs the following actions:

  1. Creates a site Web site
  2. Creates a list List list1
  3. Creates a list field FieldText field1 (which is a field of list1 list)
  4. Creates a list field FieldNumber field2 (which is a field of list1 list)
  5. Creates another list List list2
  6. Calls clientContext.ExecuteQuery() which orders the SharePoint to actually create all these SharePoint components.

I want to achieve the following:
If for some reason something goes wrong while creating field2, i.e. in the step 4, I want my code to cancel the creation of list1, field1 and field2, but I still want the site and list2 to have created.

I see the clientContext as a kind of a container where I can stack my commands and then call the ExecuteQuery method which processes these commands, i.e. pushes them to SharePoint. If I am correct, then my problem is that I am unable to clear certain commands stacked inside the clientContext object. I need to have them removed before the query gets executed. Can you show me how? Thanks.

1 Answer 1


That can be done using batch exception handling. Take a look at:

How to: Use Exception Handling Scope


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.