Last active
March 12, 2018 08:42
-
-
Save AsishP/dc014c01b64e1d7af60a4f0987e502c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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