Skip to content

Instantly share code, notes, and snippets.

@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 };
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 / 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 / SPO List Alerts.js
Last active October 13, 2021 09:27
JavaScript for Adding a Document Library Email Alert for the loggged in User
var ctx = SP.ClientContext.get_current();
this.user = ctx.get_web().get_currentUser();
this.alerts = this.user.get_alerts();
this.list = ctx.get_web().get_lists().getByTitle('Documents');
ctx.load(this.user);
ctx.load(this.alerts);
ctx.load(this.list);
@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 / Step5-LargeFileUpload-GettingContext.js
Last active February 13, 2017 11:23
Getting the Client Context for the file upload.
function getWebRequestExecutorFactory(appWebUrl, hostWebUrl, spLanguage) {
let context = new window.SP.ClientContext(appWebUrl);
const factory = new window.SP.ProxyWebRequestExecutorFactory(appWebUrl);
context.set_webRequestExecutorFactory(factory);
return context;
}
const jsomContext = (appWebUrl, hostWebUrl, spLanguage) => {
@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",
@beckettkev
beckettkev / Step3-LargeFile-Preperation.js
Created February 13, 2017 10:53
Getting started with Uploading Large Files...
import utils from './utils';
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.
if (begin < 0) begin = Math.max(begin + len, 0);
@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);
}