Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11571

Cannot create list in SharePoint 2010 using Client Object Model

$
0
0

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.


Viewing all articles
Browse latest Browse all 11571

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>