1

I was working with creating document set in a folder in Document Library using Client Side Object Model (C#). But strangely I got this error:

Save Conflict. Your changes conflict with those made concurrently by another user. If you want your changes to be applied, click Back in your Web browser, refresh the page, and resubmit your changes.

The code which I used is:

using (ClientContext clientContext = new ClientContext(siteUrl))
{
clientContext.Credentials = credentials;
List documentLibrary = clientContext.Web.Lists.GetByTitle(documentLibraryName);
ContentTypeCollection listContentTypes = documentLibrary.ContentTypes;
clientContext.Load(listContentTypes, types => types.Include(type => type.Id, type => type.Name, type => type.Parent));
var result = clientContext.LoadQuery(listContentTypes.Where(c => c.Name == contentTypeName));
clientContext.ExecuteQuery();
ContentType targetDocumentSetContentType = result.FirstOrDefault();
ListItemCreationInformation newItemInfo = new ListItemCreationInformation();
newItemInfo.UnderlyingObjectType = FileSystemObjectType.Folder;
newItemInfo.LeafName = inventionDocumentSetName;
newItemInfo.FolderUrl = siteUrl + documentLibraryName + "/" + inventionFolderName;
ListItem newListItem = documentLibrary.AddItem(newItemInfo);
newListItem["ContentTypeId"] = targetDocumentSetContentType.Id.ToString();
newListItem.Update();
documentLibrary.Update();
clientContext.ExecuteQuery();
}

I have done a lot of research on this error but not found anything useful to avoid this.

When I run the same code on SharePoint 2010 it worked successfully but when I run the same code against SharePoint 2013 Environment it gives me this error.

Let me know if you need some more details to help then please comment it.

PS: I have already gone through this post.

2

Try splitting the Create and Update into two actions

ListItem newListItem = documentLibrary.AddItem(newItemInfo);
newListItem.Update();

//HERE GET THE ITEM BY ID AGAIN AND PERFORM UPDATE
newListItem = documentLibrary.GetItemById(ItemID);
clientContext.Load(newListItem);
clientContext.ExecuteQuery();


newListItem["ContentTypeId"] = targetDocumentSetContentType.Id.ToString();
newListItem.Update();
  • It worked for me on both the environment. – Aakash Maurya Aug 2 '16 at 13:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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