Poul K. Sørensen
Poul K. Sørensen

Reputation: 17540

How to add a column value to a ClientSidePage with sharepoint pnp?

I have created a clientsidepage var page = clientContext.Web.AddClientSidePage($"{folder}/{slug}.aspx", true);

How do I now add a column value to the page?

By column value I mean, that a SharePoint administrator has under side content inside SharePoint on the page list added a custom column called "MyCustomColumn", but I can't figure out how to populate it

Upvotes: 0

Views: 153

Answers (1)

LZ_MSFT
LZ_MSFT

Reputation: 4228

We can use page.PageListItem to get the current new item, then update the field "MyCustomColumn" to the item, the code example below for your reference.

string siteUrl = "https://tenant.sharepoint.com/sites/lz";
string userName = "[email protected]";
string password = "xxx";
var securePassword = new SecureString();
foreach (char c in password.ToCharArray()) securePassword.AppendChar(c);
using (ClientContext clientContext = new ClientContext(siteUrl))
{
    clientContext.Credentials = new SharePointOnlineCredentials(userName, securePassword);
    var page = clientContext.Web.AddClientSidePage("MyModernPage.aspx",true);             
    var item = page.PageListItem;
    item["MyCustomColumn"] = "Test";
    item.Update();
    clientContext.ExecuteQuery();
}

Upvotes: 1

Related Questions