Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am working in SharePoint 2010.I am dynamically creating a list on FeatureActivation event. My list has following columns Title : Text , VisibleTo: User/People, Menu : Choice, Type : Choice.

Problem is when I try to add items dynamically it gives me following error.

Invalid data has been used to update the list item. The field you are trying to update may be read only.

As the error message suggest, there is no read only field in the list.

Please help me on finding the exact cause of this error.

oList.Fields.Add("LinkTitle", SPFieldType.Text, true);                     
oList.Fields.Add("URL", SPFieldType.Text, false);
oList.Fields.Add("ShowInNav", SPFieldType.Boolean, false);
oList.Fields.Add("VisibleTo", SPFieldType.User, false);
oList.Fields.Add("ParentID", SPFieldType.Text, false);


oListItem["Title"] = newListItem.Title;
oListItem["LinkTitle"] = newListItem.LinkTitle;
oListItem["URL"] = newListItem.URL;
oListItem["ShowInNav"] = newListItem.ShowInNav;
oListItem["VisibleTo"] = oWeb.EnsureUser("ABC");
oListItem["ParentID"] = newListItem.ParentId;
oListItem.Update();

Where newListItem is a collection of items.

Many thanks

VB

share|improve this question

1 Answer 1

up vote 1 down vote accepted

As Steve comments it's hard to guess without any code. But my guess would be that the Person(s) inserted into VisibleTo isn't on the site. Try using EnsureUser before adding them.

OK after the code has been added it's a bit easier.

Remove the following lines :

oList.Fields.Add("LinkTitle", SPFieldType.Text, true); 

and

oListItem["LinkTitle"] = newListItem.LinkTitle;

LinkTitle and LinkTitleNoMenu are two very special fields which has the same data as Title (and therefore shouldn't be updated), but different representation in views.

share|improve this answer
    
Hi Per I tried that but still I have the same error.Though user is present on site. –  V.B Jun 13 '12 at 7:57
    
Thanks per. It worked after removing the Link Title column. –  V.B Jun 13 '12 at 8:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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