0

I am trying to update a SPListItem metadata properties after inserting this document into a document library.

Fortunately though the CSOM, this is quite easy:

private void UpdateListItemProperty(object value, PropertiesEnum prop, ListItemCollection listItems, ClientContext ctx)
        {
            foreach (ListItem li in listItems)
            {
                li[EnumHelper.GetDescription(prop)] = value;
                li.Update();
            }
            ctx.ExecuteQuery();
        }

Unfortunately, I also have to do it Server Object Model, in context of SharePoint, and it does not populate boolean/date fields. Stangely, not ALL text fields populate either, but definetly some do. How do I update properties this way?

private static void UpdateListItemProperties(SPListItem listItem)
        {
listItem.Properties["MyFirstTextField"] = "Blah"; //works fine
listItem.Properties["TextField_x0020_WithSpace"] = "string"; //doesn't work
listItem.Properties["MyFirstBoolField"] = true; //doesn't work
listItem.Update();
}

Wehn I say works/doesn't work; I mean the list item properties are not updated.

Ideally I don't have to rename the columns that i am already populating fine through CSOM, just to be able to populate them through SP.

Note: in CSOM it actually uses a ListItem and in SOM it uses SPListItem

  • 1
    did you tried removing x0020 ? – Varun Verma Sep 2 '14 at 4:04
1

First thing to try:

listItem["MyFirstTextField"] = "Blah"; //works fine
listItem["TextField_x0020_WithSpace"] = "string"; //doesn't work
listItem["MyFirstBoolField"] = true; //doesn't work
listItem.Update();

Remove the Properties part.. The above actually consider you provide the Internal name of the fields, the internal name is obviously different from the display name.. I hope you are already aware as you replace space with _x0020_

  • No I most certainly was not aware, as that is exactly how IT IS required when you use the CSOM – baron Sep 2 '14 at 6:43
0

It turns out that CSOM requires the 'encoded' names, i.e. TextField_x0020_WithSpace

If you use the server object model, in context of sharepoint, you can just specify it with the space:

listItem["TextField WithSpace"] = "value";

It's an awesome undocumented feature of sharepoint that wasted a cpl hours of my time.

Isn't it great how to do the exact same thing, you have to write two completely different sets of code!

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.