Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// parse query parameter
string siteURL = req.GetQueryNameValuePairs()
.FirstOrDefault(q => string.Compare(q.Key, "siteURL", true) == 0)
.Value;
string pageName = req.GetQueryNameValuePairs()
.FirstOrDefault(q => string.Compare(q.Key, "pageName", true) == 0)
.Value;
// Get request body
dynamic data = await req.Content.ReadAsAsync<object>();
// Set name to query string or body data
siteURL = siteURL ?? data?.siteURL;
pageName = pageName ?? data?.pageName;
OfficeDevPnP.Core.AuthenticationManager am = new OfficeDevPnP.Core.AuthenticationManager();
using (var cc = am.GetSharePointOnlineAuthenticatedContextTenant(siteUrl, userName, secpass))
{
bool pageMissing = false;
try
{
ClientSidePage.Load(cc, pageName);
} catch(Exception ex1)
{
pageMissing = true;
}
if (pageMissing)
{
ClientSidePage newPage = new ClientSidePage(cc);
newPage.LayoutType = ClientSidePageLayoutType.Article;
newPage.Save(pageName);
log.Info("Site Page is created");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment