Skip to content

Instantly share code, notes, and snippets.

@AsishP
Last active March 12, 2018 08:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AsishP/dc014c01b64e1d7af60a4f0987e502c0 to your computer and use it in GitHub Desktop.
Save AsishP/dc014c01b64e1d7af60a4f0987e502c0 to your computer and use it in GitHub Desktop.
// 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