Last active
August 29, 2015 14:04
-
-
Save lesagesander/e0a4e7d4a507cd0965f0 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
public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties) | |
{ | |
var result = new SPRemoteEventResult(); | |
// Get the token from the request header. Because this is a .svc remote event receiver we use the current Operationcontext. | |
var requestProperty = (HttpRequestMessageProperty)OperationContext.Current.IncomingMessageProperties[HttpRequestMessageProperty.Name]; | |
var contextToken = TokenHelper.ReadAndValidateContextToken(requestProperty.Headers["X-SP-ContextToken"], requestProperty.Headers[HttpRequestHeader.Host]); | |
using (var clientContext = TokenHelper.CreateRemoteEventReceiverClientContext(properties)) | |
{ | |
if (clientContext != null) | |
{ | |
try | |
{ | |
//create document library | |
clientContext.Web.AddDocumentLibrary("Internal documents", true); | |
//create wiki page | |
clientContext.Web.AddWikiPage("Site Pages", "Documents.aspx"); | |
//set correct page layout to wiki page | |
clientContext.Web.AddLayoutToWikiPage("sitepages", WikiPageLayout.TwoColumns, "Documents"); | |
//get new document library | |
var internallDocLib = clientContext.Web.GetListByTitle("Internal documents"); | |
//add listviewwebparts to page | |
var internalDocsWebPartEntity = new WebPartEntity | |
{ | |
WebPartIndex = 2, | |
WebPartTitle = "Latest Internal Documents", | |
WebPartZone = "Left", | |
WebPartXml = string.Format(Globals.ListViewWebPart, internallDocLib.Id, "Latest Internal Documents") | |
}; | |
//params: pageslibrary url, webpartentity, wiki page, table row, table column, addSpace under web part | |
clientContext.Web.AddWebPartToWikiPage("sitepages", internalDocsWebPartEntity, "documents.aspx", 1, 1, true); | |
} | |
catch | |
{ | |
//write logging information | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment