I am creating a list using COM for Sharepoint 2010.

below is a snippet for the same:

        CredentialCache myCache = new CredentialCache();
        myCache.Add(new Uri("myURL"), "NTLM", myCred);

        // declare the ClientContext Object 
        SP.ClientContext _clientcontext = new SP.ClientContext(_context);
        SP.Web _site = _clientcontext.Web;
        // declare a ListCreationInfo 
        SP.ListCreationInformation _listcreationinfo = new SP.ListCreationInformation();

        // set the Title and the Template of the List to be created 
        _listcreationinfo.Title = "NewListFromCOM";
        _listcreationinfo.TemplateType = (int)SP.ListTemplateType.GenericList;

        // Call the add method to the ListCreatedInfo 
        SP.List _list = _site.Lists.Add(_listcreationinfo);

        // Add Description field to the List 
        for(int i=1;i<4;i++)
            someStr = "<Field Type='Number' DisplayName='Col0" + i + "'></Field>";
        SP.Field _Description = _list.Fields.AddFieldAsXml(@someStr, true, SP.AddFieldOptions.AddToDefaultContentType);

        // declare the List item Creation object for creating List Item 
        SP.ListItemCreationInformation _itemcreationinfo = new SP.ListItemCreationInformation();

        // call the additem method of the list to insert a new List Item 
        SP.ListItem _item = _list.AddItem(_itemcreationinfo);

        _item["Title"] = "New Item from Client Object Model";

        for (int i = 1; i < 4; i++)
            _item[someStr] = 100 + i;

        // call the update method 

I wanted to create columns like = Col01, Col02, Col03. Then create an item in the list, and update.

The list gets created successfully, but on updating I get an error:

        Column 'Col01' does not exist. It may have been deleted by another user.

Could someone pls help why this is happening? The list exists, and I have tried deleting it and running the code again. It doesnt work. I have tried using the static name (="_x0043_ol01") for Col01 but can't figure out how.

Really appreciate your help.

  • I am looping through Column names, as actually I would be creating about 30 such columns of type=number and its tiring to do this manually. Thanks for your help! – xcentaur Dec 26 '12 at 9:54
  • call _list.Update(); after the loop of adding fields – Arsalan Adam Khatri Dec 26 '12 at 10:03
  • @ArsalanAdamKhatri thanks for the comment. Now the error message has gone. But the new item I am inserting, that does not get entered into the list. – xcentaur Dec 26 '12 at 10:25
  • might be a stupid comment but do you have permissions to add list item, and also can you check if you get any error in ULS log – Muhammad Raja Dec 26 '12 at 10:29
  • Haha, thanks for the idea, but I've checked - yes. I've manually created a list. I am able to programmatically add list items to it. – xcentaur Dec 26 '12 at 10:33

If what Arsalan suggested doesn't help then try loading column before trying to update them, as it has been done in this article

Also can you go to list through browser and check if columns are actually being created or not.


Try enabling the retention in the parent content type and re-publish the associated content type.

Similiar Problem

Hope it helps.

  • thanks for the answer. The columns are being created, I checked in datasheet view. But the row isn't getting added? Going thru Mike's article. This was from where I understood the original code as well, but this did not work. Will try and update here in a minute! – xcentaur Dec 26 '12 at 10:28
  • I tried this again. With a new listname. Even after adding _list.update(), now I am still getting the same error message. Again, list is being created from COM, but thenew item is not added. – xcentaur Dec 26 '12 at 10:36
  • I updated my answer :) – Muhammad Raja Dec 26 '12 at 10:41
  • thanks for the update. but I am not able to figure out how to change the retentional policy? After going through the link. also, now the regular updates are not working. manually created list also, i am not able to add list item. pls help! im completely stuck, although this was working before. – xcentaur Dec 26 '12 at 12:08

call _list.Update(); after the loop of adding fields

Use following code for adding List Item:

// call the additem method of the list to insert a new List Item 
SP.ListItem _item = _list.AddItem();

_item["Title"] = "New Item from Client Object Model";

for (int i = 1; i < 4; i++)
        _item[someStr] = 100 + i;

// call the update method 

No need for ItemCreationInformation

I hope this helps


In my list, the Static Name and Internal Name seem to be the same. I am not sure if this is the case normally. Using the Display Name was definitely failing.

Here is what worked for me:

  1. adding _list.update();

  2. Using static name as -

    _item["_x0043_ol03"] = comboBox1.SelectedText;

I just want to say thank you to the community, specially @ArsalanAdamKhatri and @TimeToShine . Thank you for all the time and energy you put into helping queries of us newbies! :)

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.