Skip to content

Instantly share code, notes, and snippets.

@lesagesander
Last active August 29, 2015 14:04
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 lesagesander/e0a4e7d4a507cd0965f0 to your computer and use it in GitHub Desktop.
Save lesagesander/e0a4e7d4a507cd0965f0 to your computer and use it in GitHub Desktop.
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