Cannot create list in SharePoint 2010 using Client Object Model
Posted
by Boris
on Stack Overflow
See other posts from Stack Overflow
or by Boris
Published on 2010-05-19T09:36:46Z
Indexed on
2010/05/19
9:40 UTC
Read the original article
Hit count: 689
sharepoint2010
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.
© Stack Overflow or respective owner