none
SharePoint List via CSOM: set description or custom metadata on the list? RRS feed

  • Question

  • I am working with a list on SharePoint Online that I maintain through my software via CSOM and the SharePoint.Client v16 in VS2015.

    I have a few hundreds of items in the list, and my custom fields there. It's a generic list defined first in SharePoint.

    I need also to set one or 2 metadata on the list directly, i.e. NOT on the items but valid for all of them. Typically, it will be information of the source data that I read through my software to update the list.

    Can we add custom metadata on a list (NOT collumn)?

    I first though about setting simply the Description field, as follow:

    List spList = clientContext.Web.Lists.GetByTitle(listTitle);
    clientContext.Load(spList, l => l.Description);
    clientContext.ExecuteQuery();
    if (!string.IsNullOrEmpty(description) && spList.Description != description)
    {
         spList.Description = description;
         clientContext.ExecuteQuery();
    }

    This piece of code run properly and the description is supposed to be set.
    BUT when I read it again, it stays always empty  ( "" ).

    Why??

    Friday, April 7, 2017 10:22 AM

Answers

  • ok, my bad, I forgot the spList.Update();

    And for the metdata, the RootFolder Properties are working well.
    Here is the fix/working example:

    List spList = clientContext.Web.Lists.GetByTitle(listTitle);
    clientContext.Load(spList, l => l.Description, l.RootFolder.Properties);
    clientContext.ExecuteQuery();
    if (!string.IsNullOrEmpty(description) && spList.Description != description)
    {
         spList.Description = description;
         spList.Update();
         spList.RootFolder.Properties["SourceDescription"] = description;
         spList.RootFolder.Update();
         clientContext.ExecuteQuery();
    }

    • Marked as answer by EricBDev Friday, April 7, 2017 10:42 AM
    Friday, April 7, 2017 10:42 AM

All replies

  • I just found a possible solution for metadata:

    http://sharepoint.stackexchange.com/questions/208319/create-list-property-like-description-field

    https://mohamedramadanahmed.wordpress.com/2012/02/15/add-meta-properties-to-sharepoint-list/

    I am testing that!

    Friday, April 7, 2017 10:25 AM
  • ok, my bad, I forgot the spList.Update();

    And for the metdata, the RootFolder Properties are working well.
    Here is the fix/working example:

    List spList = clientContext.Web.Lists.GetByTitle(listTitle);
    clientContext.Load(spList, l => l.Description, l.RootFolder.Properties);
    clientContext.ExecuteQuery();
    if (!string.IsNullOrEmpty(description) && spList.Description != description)
    {
         spList.Description = description;
         spList.Update();
         spList.RootFolder.Properties["SourceDescription"] = description;
         spList.RootFolder.Update();
         clientContext.ExecuteQuery();
    }

    • Marked as answer by EricBDev Friday, April 7, 2017 10:42 AM
    Friday, April 7, 2017 10:42 AM
  • Hi,

    Glad to hear that you solve this issue, thanks for your sharing.

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Monday, April 10, 2017 6:14 AM
    Moderator