Skip to content

Instantly share code, notes, and snippets.

View AsishP's full-sized avatar

Asish Padhy AsishP

  • Sydney, Australia
View GitHub Profile
@AsishP
AsishP / UserNotFoundIssueFix
Created November 6, 2017 22:36
User not found in SharePoint CSOM code
FieldUserValue authorUser = (FieldUserValue) listItem["Author"];
User author = web.EnsureUser(authorUser.LookupValue);
bool byPassAuthorCreation = false;
try
{
context.Load(author);
context.ExecuteQuery();
}catch(Exception ex)
{byPassAuthorCreation=true;}
public static void InitializeService(DataServiceConfiguration config)
{
// TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
config.UseVerboseErrors = true;
}
ListTemplateCollection templates = context.Site.GetCustomListTemplates(context.Web);
context.Load(templates);
context.ExecuteQuery();
log.Info("Templates Loaded");
// Initialize list or library creation info
var template = templates.First(listTemp => listTemp.Name == "<name of template>");
var listCreationInfo = new ListCreationInformation();
listCreationInfo.Title = LibName;
log.Info("Inheriting permissions");
//Inherit permissions if broken
rListitem.ResetRoleInheritance();
transList.ResetRoleInheritance();
log.Info("Now let's start breaking the permissions again");
// Break permissions
rListitem.BreakRoleInheritance(false, false);
transList.BreakRoleInheritance(false, false);
RoleAssignmentCollection collRoleAssign = destList.RoleAssignments;
public static void InitializeService(DataServiceConfiguration config)
{
// TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
// Examples:
config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
// config.SetServiceOperationAccessRule("MyServiceOperation", ServiceOperationRights.All);
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
config.UseVerboseErrors = true;
}
@AsishP
AsishP / property bag update normal
Created February 8, 2018 02:45
Set property bag of web object normally using CSOM
context.Web.AllProperties[“PropertyBagValue1”] = “Property”
context.Web.Update()
context.Web.ExecuteQuery()
@AsishP
AsishP / Update property bag modern SP site
Created February 8, 2018 02:48
Update Property bag in Modern Team Sites
using Microsoft.Online.SharePoint.TenantAdministration;
using (var contextTenant = new ClientContext(<spTenantUrl>))
{
contextTenant.Credentials = new SharePointOnlineCredentials(<username>, <secpass>);
Tenant tSP = new Tenant(contextTenant);
tSP.SetSiteProperties(<groupurl>, noScriptSite: false);
contextTenant.ExecuteQuery();
}
contextGroup.Web.SetPropertyBagValue("ProvisioningStatus", "Completed");
{
"$schema": "schema.json",
"actions": [
{
"verb": "applyTheme",
"themeName": "Custom Dark Blue custom"
},
{
"verb": "createSPList",
"listName": "Training Registration",
{
"type": "object",
"properties": {
"webUrl": {
"type": "string"
},
"parameters": {
"type": "object",
"properties": {
"event": {
Write-Output "Incoming request for '$in'"
Connect-PnPOnline -AppId $env:AppId -AppSecret $env:AppSecret -Url $in
Write-Output "Connected to site"
Apply-PnPProvisioningTemplate -Path D:\home\site\wwwroot\<function name>\<template>.xml