Skip to content

Instantly share code, notes, and snippets.

using System.Collections.Generic;
// accesses a control by ID (i.e. a checkbox/button/textbox etc)
private static Control FindControlIterative(Control root, string id)
{
Control ctl = root;
LinkedList<Control> ctls = new LinkedList<Control>();
while (ctl != null)
{
if (ctl.ID == id)
@zplume
zplume / UpdateUserInfo.ps1
Created June 26, 2013 08:09
Update the mobile number and work number values (from Active Directory) for all users in the User Information List, for all site collections in the specified web application.
##### ABOUT #####
# This script updates the mobile number and work number values
# for all users in the "User Information List" for all site collections
# in the specified web application (see variables below)
##### VARIABLES #####
$webAppURL = "http://mywebapp"
$logPath = "C:\temp\UpdateUserInfo\UpdateUserInfo"
@zplume
zplume / LinqReflectionConsole.cs
Last active December 20, 2015 03:09
Reflection, Linq & Properties demo
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using LS.Extensions;
using Properties;
namespace Properties
{
@zplume
zplume / LS.Extensions.cs
Last active December 27, 2016 06:20
A collection of extension methods both for general .NET and SharePoint 2010/2013 specific usage
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web.UI;
using System.Xml; // requires System.Xml reference
using System.Xml.Linq; // requires System.Xml.Linq reference
@zplume
zplume / AJAXFrames.js
Last active August 29, 2015 14:02
Global (tenant scoped) HTML/JS 'web part' framework for SharePoint Online
// replacement function for console.log(), which avoids 'undefined' exception in IE 8
window.LogMsg = function (msg) {
if (window.console) {
console.log(msg);
}
};
// set up root namespaces
window.LS = window.LS || {};
LS.AJAXFrames = LS.AJAXFrames || {};
@zplume
zplume / GetSharePointPermissionLevels.js
Last active July 7, 2023 14:31
Get an array of Permission Levels (Role Definitions) for the current site using REST
// This script returns an array of Role Definition objects, containing the Permission Levels for the site
// See http://msdn.microsoft.com/en-us/library/office/jj244931(v=office.15).aspx for examples of how to use the
// SP.PermissionKind object to assign permissions to a Role Definition
// replacement function for console.log(), which avoids 'undefined' exception in IE 8
window.LogMsg = function (msg) {
if (window.console) {
console.log(msg);
}
@zplume
zplume / FieldsToConstants.ps1
Last active August 29, 2015 14:02
A PowerShell utility script that outputs C# code listing all custom fields in the RootWeb of a site collection (filtered by a field name prefix) as a set of static classes with constant string properties for Id and Name.
$siteUrl = "http://site/collection/url"
$fieldPrefix = "ClientName_"
$outputPath = "c:\temp\Fields.cs"
$site = Get-SPSite $siteUrl
$fields = $site.RootWeb.Fields
$output = ""
$newLine = "`r`n"
$tab = "`t"
@zplume
zplume / LS.SP.JSOM.js
Last active October 2, 2024 23:48
SharePoint 2013 REST / JSOM / Utility functions (work in progress)
(function() {
var nsName = "LS"; // root namespace name
var ns = window[nsName]; // root namespace alias
var utils = ns.Utils; // utils alias
ns.SP = ns.SP || {};
ns.SP.JSOM = {
Data: {
Sites: {} // cache for Taxonomy terms JSON
},
@zplume
zplume / HTMLInputPasswordValidation.html
Last active December 5, 2019 08:16
HTML 5 / Kendo UI client-side validation for a password field with basic complexity requirements
<!--ASP.NET-->
<asp:Textbox runat="server" ClientIdMode="Static" type="password" id="PasswordTextbox" name="PasswordTextbox" pattern="^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9]).{8,}$" validationmessage="Please enter a password which is at least 8 characters long and contains a lowercase character, an uppercase character and a number" required />
<!--HTML-->
<input type="password" id="PasswordTextbox" name="PasswordTextbox" pattern="^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9]).{8,}$" validationmessage="Please enter a password which is at least 8 characters long and contains a lowercase character, an uppercase character and a number" required />
<!--Kendo UI Validator: http://demos.telerik.com/kendo-ui/validator/index -->
@zplume
zplume / SP.MDS.OnPageLoad.js
Last active November 11, 2021 13:32
Example code to ensure that a function is executed on all page loads, including MDS page loads (where partial page loading is used for navigation rather than full postbacks).
// define a global function to execute
function $_global_onMDSPageLoad() {
// code to execute on page load goes here
}
ExecuteOrDelayUntilScriptLoaded(function () {
if (typeof asyncDeltaManager != "undefined")
asyncDeltaManager.add_pageLoaded($_global_onMDSPageLoad); // execute on MDS page load
else
$_global_onMDSPageLoad(); // execute on non-MDS page load