Skip to content

Instantly share code, notes, and snippets.

Avatar

Asish Padhy AsishP

  • Sydney, Australia
View GitHub Profile
@AsishP
AsishP / UserNotFoundIssueFix
Created Nov 6, 2017
User not found in SharePoint CSOM code
View UserNotFoundIssueFix
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;}
View Azure WCF Data Service Method
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;
}
View Library creation with Template
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;
View Permissions Management
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;
View Azure WCF Service
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 Feb 8, 2018
Set property bag of web object normally using CSOM
View property bag update normal
context.Web.AllProperties[“PropertyBagValue1”] = “Property”
context.Web.Update()
context.Web.ExecuteQuery()
@AsishP
AsishP / Update property bag modern SP site
Created Feb 8, 2018
Update Property bag in Modern Team Sites
View Update property bag modern SP site
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");
View JSON Custom List through Site Script
{
"$schema": "schema.json",
"actions": [
{
"verb": "applyTheme",
"themeName": "Custom Dark Blue custom"
},
{
"verb": "createSPList",
"listName": "Training Registration",
View JSON Request Trigger Site Script in Flow
{
"type": "object",
"properties": {
"webUrl": {
"type": "string"
},
"parameters": {
"type": "object",
"properties": {
"event": {
View PnP PowerShell Apply Template
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