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