Skip to content

Instantly share code, notes, and snippets.

View BobGerman's full-sized avatar

Bob German BobGerman

View GitHub Profile
@BobGerman
BobGerman / WidgetHelperUse.ts
Last active August 13, 2019 19:39
This service provides the on-page content (_spPageContextInfo and __REQUESTDIGEST) often used when making REST calls in JavaScript from a SharePoint page. This content is not provided on Modern pages with the SharePoint Framework, requiring updates to any REST calls that may have depended on it. This service dynamically populates the data on any…
// (within a SharePoint Framework web part)
import { WidgetHelper } from './services/widgetHelper';
// ...
public render(): void {
var helper = new WidgetHelper(this.context);
helper.ensureClassicPageProps(true).then (() => {
const element: React.ReactElement<IEventsProps > = React.createElement(
Events,
@BobGerman
BobGerman / csomHelper.csx
Last active February 20, 2023 11:14
Sample code for calling SharePoint CSOM from an Azure Function
using Microsoft.IdentityModel.Clients.ActiveDirectory;
using Microsoft.SharePoint.Client;
using System.Security.Cryptography.X509Certificates;
public static class csomHelper {
private static string ClientId = "<fill in app ID>";
private static string Cert = "myCert.pfx"; // Fill in name of your cert file and upload it
private static string CertPassword = "<fill in cert password>"; // TODO: Explore more secure place for this
private static string Authority = "https://login.windows.net/<tenant>.onmicrosoft.com/";
@BobGerman
BobGerman / Setup-SiteClassificationsSample.ps1
Created September 22, 2017 20:00
Sample PowerShell to set up SP Online site classifications
$me = Get-Credential
Import-Module AzureADPreview
Connect-AzureAD -Credential $me
# Create the new setting
$template = Get-AzureADDirectorySettingTemplate | Where-Object {$_.DisplayName -eq "Group.Unified"}
$setting = $template.CreateDirectorySetting()
$setting["UsageGuidelinesUrl"] = "http://www.microsoft.com/"
$setting["ClassificationList"] = "Secret, Confidential, Internal, Public"
@BobGerman
BobGerman / Setup-ModernSiteSample.ps1
Created September 22, 2017 21:07
Provisioning a modern team site with PnP PowerShell
Connect-PnPMicrosoftGraph -Scopes "Group.ReadWrite.All","User.Read.All"
$group = New-PnPUnifiedGroup -DisplayName "xxx" -Description "xxx" -MailNickname "xxx"
-Members "user@tenant.onmicrosoft.com" -IsPrivate
Connect-PnPOnline $group.SiteUrl
# Here you would normally apply a Provisioning Template to create lists, libraries, web parts etc.
# based on a "template" site. Instead, I just want to show placing a couple web parts in a
# 2-column section to show how that works: