Skip to content

Instantly share code, notes, and snippets.

@beckettkev
beckettkev / CreateDemoUsers.csv
Last active March 7, 2019 16:57
A CSV file with
We can make this file beautiful and searchable if this error is corrected: It looks like row 8 should actually have 11 columns, instead of 10. in line 7.
Firstname,Lastname,StreetAddress,City,PostalCode,Country,Password,Department,Office,UserPrincipalName,DisplayName
Alan,Partridge,1443 Bloomfield Way,London,EN5 1AD,UK,aaiQu9soogae,Sales,Barnet,Alan.Partridge@REPLACEWITHTENANTDOMAIN.onmicrosoft.com,Alan Partridge
Bella,Barlow,103 Hedge Street,London,EN5 1AD,UK,S111olaek9,Marketing,Barnet,Bella.Barlow@REPLACEWITHTENANTDOMAIN.onmicrosoft.com,Bella Barlow
Keith,Clarke,1342 Freshour Circle,London,EN5 1AD,UK,di6h2oYai,Finance,Barnet,Keith.Clarke@REPLACEWITHTENANTDOMAIN.onmicrosoft.com,Keith Clarke
Tilly,Brie,1724 Burke Street,London,EN5 1AD,UK,abh7aiVbi,IT,Barnet,Tilly.Brie@REPLACEWITHTENANTDOMAIN.onmicrosoft.com,Tilly Brie
Tim,Apple,1680 Fannie Street,London,EN5 1AD,UK,ux4OopaeKo7,IT,Barnet,Tim.Gray@REPLACEWITHTENANTDOMAIN.onmicrosoft.com,Tim Gray
Mark,Davis,3583 Woodland Terrace,London,EN5 1AD,UK,abcikeiloh7,IT,Barnet,Mark.Davis@REPLACEWITHTENANTDOMAIN.onmicrosoft.com,Mark Davis
Ralph,Goodlow,2639 Orphan Road,London,EN5 1AD,UK,9d!p3ohhu,Finance,Barnet,Ralph.Goodl
@beckettkev
beckettkev / CreateDeveloperTenantUsers.ps1
Created March 7, 2019 13:43
Creates a bunch of users in a tenant, given a csv file full of users
#Install-Module MSOnline
$users = ipcsv ./CreateDemoUsers.csv;
Connect-MsolService
$users | ForEach-Object {
Write-Host "Adding $($_.DisplayName)..." -foregroundcolor green;
$user = $_.psobject.properties | % { $ht = @{} } { $ht[$_.Name] = $_.Value } { $ht };
@beckettkev
beckettkev / LargeFileUpload.js
Last active January 22, 2019 03:13
Uploading large files using the start, continue and finish upload functions with SharePoint 2013.
import utils from './utils';
// First we need to make sure we are backwards compatible with IE (no ArrayBuffer.slice)
if (!ArrayBuffer.prototype.slice) {
ArrayBuffer.prototype.slice = function (begin, end) {
let len = this.byteLength;
begin = (begin|0) || 0;
end = end === (void 0) ? len : (end|0);
// Handle negative values.
import * as React from 'react';
import * as ReactDom from 'react-dom';
import { Version } from '@microsoft/sp-core-library';
import {
BaseClientSideWebPart,
IPropertyPaneConfiguration,
WebPartContext
} from '@microsoft/sp-webpart-base';
import * as strings from 'MyWebPartStrings';
import MyComponent from './components/MyComponent';
@beckettkev
beckettkev / SharePoint Search Navigation Nodes.js
Created March 18, 2016 14:51
How to get the SharePoint Search Navigation Nodes via the REST API
/*
Replace <TENANT> with your tenant sub domain (e.g. MyCompany) and <SITE> with the site or site collection (e.g. sites/news)
*/
https://<TENANT>.sharepoint.com/<SITE>/_api/web/Navigation/GetNodeById(1040)/Children
@beckettkev
beckettkev / SPO Get User Alerts.js
Created March 15, 2017 17:43
Get an individuals Alerts - SPO
var ctx = SP.ClientContext.get_current();
this.user = ctx.get_web().get_currentUser();
this.alerts = this.user.get_alerts();
ctx.load(this.user);
ctx.load(this.alerts);
ctx.executeQueryAsync(()=> {
var enumerator = this.alerts.getEnumerator();
@beckettkev
beckettkev / Step7-LargeFileUpload-UploadChunk.js
Last active February 13, 2017 11:55
This recursive function uploads chunks to a file in a document library
//the final REST call is made to get the file information after it has been fully uploaded (especially the file list item id)
function getFileInformation(libraryPath, fileName, resolve, reject) {
let endpoint = String.format("{0}/_api/sp.appcontextsite(@target)/web/getfilebyserverrelativeurl(@libraryPath)/ListItemAllFields?@target='{3}'&@libraryPath='/sites/assetdatabase/{1}/{2}'",
utils.getSpContaxtUrlParams().appWebUrl, libraryPath, fileName, utils.getSpContaxtUrlParams().hostWebUrl);
const headers = {
"Accept": "application/json; odata=verbose"
};
@beckettkev
beckettkev / Step6-LargeFileUpload-Start.js
Created February 13, 2017 11:36
Starting the large file upload using chunks
//Helper method - depending on what chunk of data we are dealing with, we need to use the correct REST method...
function getUploadMethod(offset, length, total) {
if (offset + length + 1 > total) {
return 'finishupload';
} else if (offset === 0) {
return 'startupload';
} else if (offset < total) {
return 'continueupload';
}
@beckettkev
beckettkev / Utils.js
Last active February 13, 2017 11:28
Helper functions for extracting the App Web and Host URL - JavaScript (es6)
function getDocumentQueryStrings() {
const sections = document.URL.split('?');
return sections.length > 1 ? sections[1].split('&') : [];
}
function S4() {
return (((1 + Math.random())*0x10000)|0).toString(16).substring(1);
}
@beckettkev
beckettkev / Step4-LargeFileUpload-DummyFile.js
Last active February 13, 2017 11:25
Creating a dummy file for the beginning of the Large File upload process.
//this method sends the REST request using the SP RequestExecutor.js
function executeAsync(endPointUrl, data, requestHeaders) {
return new Promise((resolve, reject) => {
// remember that utils script we created?
let executor = new SP.RequestExecutor(utils.getSpContaxtUrlParams().appWebUrl);
// Send the request.
executor.executeAsync({
url: endPointUrl,
method: "POST",