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

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.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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

How to: Use Exception Handling Scope

share|improve this answer
    
Very good article! Thanks a bunch! –  Boris Nov 18 '11 at 14:13
add comment

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.