I want to change the content type of a folder in a sharepoint site using GraphServiceClient
. The goal behind this, is to attach custom columns to the folder and store values in those columns.
I access the folder like this:
var fo = await GraphClient.Drives[id].Items[_folderId].GetAsync(
c => c.QueryParameters.Expand = new[] { "ListItem" }
);
I’ve read that the ContentType can only be applied to the corresponding ListItem
. So I access it like this:
var foli = fo.ListItem;
Now, I check the ContentType
if (foli.ContentType.Name == "Ordner") // "Ordner" is German for Folder
{
//loop through available ContentTypes
var ct = await GraphClient.Sites[id].ContentTypes.GetAsync();
foreach (var item in ct.Value)
{
//find id of new ContentType
if (item.Name == "newContentType")
{
var c = item;
//What do I need to write here?
foli.ContentType = c; // does not work, because ContentTypeInfo is needed instead of ContentType
}
}
}