0

I'm using Client Object Model to update a list on SharePoint.

The list is very simple, it only has 3 columns ([Title], [Author], [Year Published])

[Title] is the standard column added by default,

[Author] is my own column and it is a string field (it's not pointing to User, it's just plain text)

and [Year Published] published is a Number.

all fields are marked as required.

string strUrl = "http://server/sites/training";
using (SPSite oSite = new SPSite(strUrl))
{
    using (SPWeb oWeb = oSite.OpenWeb())
    {
        SPList list = oWeb.Lists["Books"];
        SPListItem book = list.AddItem();
        book["Title"] = "SQL Server Internals";
        book["Author"] = "Mc Fredy";
        book["Year Published"] = 2015;
        book.Update();
    }
}

I get exception on book.Update();

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

I looked into everything I found on web but did not find any answer. Please advise.

1 Answer 1

0

Author is an internal field for every SharePoint list which specifies who created the list item. Its display name is Created By. In your case when you created Author column the internal name of this column must have changed to something else like Author0 or any other value. So first go to

List Settings -> In Column section select Author-> From page URL get value of query string parameter Field and use that in your code

So your line of code will change most probabily like this

book["Author0"] = "Mc Fredy"
1
  • Thank you @Shashank. I got my answer on stackoverfkow but it's good to have the answer here as well so it'll be helpful
    – user75190
    Commented Jun 2, 2018 at 3:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.