Adding tags to SharePoint file with Graph Service Client

ThibaultVerlinde-4578 120 Reputation points
2024-04-15T12:55:23.17+00:00

Hiya,

I'm currently working on a project where the goal is to automatically update SharePoint. Recently, I stumbled upon a problem with adding tags to an item. I have a multi choice property in SharePoint, but I can't seem update this with the graph api. I specifically want it to be a multi choice property/tag. I'm using the Microsoft.Graph SDK. All permissions are present to connect/view/edit the SharePoint page.

The intended use would be that there are multiple values assigned to the same key. The column is a selection column with multipled values enabled.

Any help would be appreciated! Code snippet is below

var tags = new List<string> {date, someLaterDate};

var requestBody = new FieldValueSet
{
    AdditionalData = new Dictionary<string, object>
    {
        { "Time", tags}
    }
};

await _graphServiceClient.Sites[siteId].Lists[listId].Items[listItem.Id].Fields.PatchAsync(requestBody);
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,658 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,266 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. AllenXu-MSFT 16,091 Reputation points Microsoft Vendor
    2024-04-16T06:28:19.48+00:00

    Hi @ThibaultVerlinde-4578,

    It seems that the error you are receiving is because the "Time" field is not recognized. In order to update a multi-choice column in SharePoint using the Microsoft Graph SDK, you need to specify the internal name of the column. You can find the internal name of the column by going to the column settings page in SharePoint and looking at the URL. The internal name will be in the URL after "Field=".

    Reference: https://sharepointstuff.com/2022/02/09/find-internal-column-name/.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.