Skip to content

Instantly share code, notes, and snippets.

View phillipharding's full-sized avatar

Phil Harding phillipharding

View GitHub Profile
json = [
{
key: 1,
id: 1,
label: "Parent #1",
isexpanded: false,
children: [
{
key: 11,
id: 11,
@phillipharding
phillipharding / Get Paged Items from a Large List using RenderListDataAsStream
Last active July 14, 2020 16:24
Gets Items from a Large Document Library/List (over 5000 items) using a Paged RenderListDataAsStream
import { sp } from "@pnp/sp/presets/all";
(async () => {
console.clear();
const doPagedQuery = (folder: string, rowLimit: number, scope: "Files"|"Folders", pageToken?: string) => {
const list = sp.web.getList('/sites/EDMS_InformationGovernance/Shared%20Documents');
return list.renderListDataAsStream({
ViewXml: `
<View Scope="RecursiveAll">

NVM version

nvm --version

List versions of Node installed

nvm ls --no-alias

List current version of Node

nvm current

Use the specified version of Node

~ # % & * { } + \ / : < > ? | " .

REGEX

[~#%&*{}+\\/:<>?|'".]+
const hasInvalidCharacters = teamName.match(/[~#%&*{}+\\/:<>?|'".]+/gi);
@phillipharding
phillipharding / Remove .DS_Store files.sh
Created April 28, 2020 16:34
Recursively removes .DS_Store files
## Recursively Remove .DS_Store
# Show
find . -name '.DS_Store' -type f
# Remove
find . -name '.DS_Store' -type f -delete
@phillipharding
phillipharding / Get O365 Groups using AdalJS and Graph on Classic SP Page.js
Last active April 1, 2020 14:45
Get Office 365 Groups and Current User Profile using the Graph API and AdalJS to acquire access tokens
console.clear();
/* Logging levels
0: Error
1: Warning
2: Info
3: Verbose
*/
(function() {
/* LOAD ADAL.JS onto the page
public async uploadFileToSharePoint(documentLibrary: string, webUrl: string, fileName: string, fileB64: any): Promise <any> {
try {
const web = new Web(webUrl);
documentLibrary = documentLibrary.replace(location.origin, "");
console.log(documentLibrary);
/* const rs: FileAddResult = await web.getFolderByServerRelativeUrl(documentLibrary).files.add(fileName,fileB64,true); */
const rs: FileAddResult = await web.getFolderByServerRelativeUrl(documentLibrary)
.files.addChunked(
fileName,
References:
- https://gist.github.com/zplume/9f4c1a658517802701deff3473f23a60
- https://gist.github.com/zplume/21248c3a8a5f840a366722442cf9ee97
- https://blog.velingeorgiev.com/createcopyjobs-api-copy-move-SharePoint-files-folders
- See also: https://gist.github.com/zplume/9f4c1a658517802701deff3473f23a60
"NameConflictBehavior":0 = Fail
"NameConflictBehavior":1 = Replace
"NameConflictBehavior":2 = Rename at destination (Keep Both)
Based on similar bejaviour at: https://docs.microsoft.com/en-us/graph/api/resources/driveitem?view=graph-rest-1.0
POST https://platinumdogsconsulting.sharepoint.com/sites/hubsitetest/_api/site/GetCopyJobProgress
HEADERS
{
Accept: application/json;odata=verbose
Content-Type: application/json;odata=verbose
X-RequestDigest: <<site form digest>>
}
BODY
{
"copyJobInfo": {
@phillipharding
phillipharding / Chrome Snippets MBP16.json
Last active January 10, 2020 12:39
To export: let exportSnippets; InspectorFrontendHost.getPreferences(_ => { exportSnippets = JSON.parse(_.scriptSnippets) }); copy(exportSnippets);
importSnippets = [
{
"id": "2",
"name": "Print Display ListForm using Dialog",
"content": "function onListFormPrintViewDialogClosed(dialogResult, returnValue) {\n console.log(\"Print View Dialog closed, result: \" + dialogResult);\n}\n\nfunction showListFormPrintViewDialog(e) {\n e.preventDefault();\n var formUrl = e.data && e.data.url && e.data.url.length ? e.data.url : '';\n if (e.data && (!e.data.url && !e.data.url.length)) {\n /* no url supplied, get the DispForm url for the current listitem form */\n var formCtxName = ($(\"*[id$='ClientFormPlaceholder']\")\n .attr('id')\n .replace(/ClientFormPlaceholder/gi,'')) || \"\";\n var formCtx = window[formCtxName+\"FormCtx\"];\n var listItemId = formCtx && formCtx.ItemAttributes\n ? formCtx.ItemAttributes.Id \n : 0;\n formUrl = formCtx.RedirectInfo\n ? formCtx.RedirectInfo.listRootFolderUrl + \"/DispForm.aspx?ID=\" + listItemId