Cannot create list in SharePoint 2010 using Client Object Model
- by Boris
I am trying to utilize SharePoint 2010 Client Object Model to create a List based on a custom template. Here's my code:
public void MakeList(string title, string listTemplateGUID, int localeIdentifier)
{
string message;
string listUrl;
List newList;
Guid template;
ListCreationInformation listInfo;
Microsoft.SharePoint.Client.ListCollection lists;
try
{
listUrl = title.Replace(spaceChar, string.Empty);
template = GetListTemplate((uint)localeIdentifier, listTemplateGUID);
listInfo = new ListCreationInformation();
listInfo.Url = listUrl;
listInfo.Title = title;
listInfo.Description = string.Empty;
listInfo.TemplateFeatureId = template;
listInfo.QuickLaunchOption = QuickLaunchOptions.On;
clientContext.Load(site);
clientContext.ExecuteQuery();
lists = site.Lists;
clientContext.Load(lists);
clientContext.ExecuteQuery();
newList = lists.Add(listInfo);
clientContext.ExecuteQuery();
}
catch (ServerException ex)
{
//...
}
}
Now, this particular part,
newList = lists.Add(listInfo);
clientContext.ExecuteQuery();
the one that is supposed to create the actual list, throws an exception:
Message: Cannot complete this action. Please try again.
ServerErrorCode: 2130239231
ServerErrorTypeName: Microsoft.SharePoint.SPException
Could anyone please help me realize what am I doing wrong? Thanks.