I want to add some metadata to my modern Team Site.
I can achieve this by simply adding columns to the Site Pages library in the site contents.
Now I want to do the same thing programmatically using CSOM.
I use the following code for that purpose:
var pages = siteContext.Web.Lists.GetByTitle("Site Pages");
var fieldCreationInformation = new OfficeDevPnP.Core.Entities.FieldCreationInformation(fieldType)
{
DisplayName = fieldName,
InternalName = fieldName.Replace(" ", ""),
AddToDefaultView = true,
Required = false,
Id = Guid.NewGuid()
};
pages.CreateField(fieldCreationInformation);
This works - the fields are getting added to the pages library, however they don't appear as the properties when I'm editing the page, unlike the columns added in the GUI.
Why? How can I add columns programmatically and see them as page properties?