Skip to content

Instantly share code, notes, and snippets.

@chrisobriensp
chrisobriensp / Accordion_ListInstance_Elements.xml
Created January 20, 2013 14:46
XML used to provision the list instance used with jQuery UI accordion. References the list template type used with JSLink.
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<ListInstance Title="Accordion list" OnQuickLaunch="TRUE" TemplateType="11000" Url="Lists/AccordionList" Description="A list which shows it's items in a fancy graphical way">
<Data>
<Rows>
<Row>
<Field Name="Title">Using the Content Search web part (and understanding SP2013 search)</Field>
<Field Name="AccordionItemDescription">Meeting client requirements with SharePoint often involves aggregating items somehow – often we want to display things like “all the overdue tasks across all finance sites”, or “navigation links to all of the subsites of this area” or “related items (e.g. tagged with the same term)” and so on. In SharePoint 2010 there have been two main ways of accomplishing this.</Field>
</Row>
<Row>
@chrisobriensp
chrisobriensp / CookieHelper.js
Created January 28, 2013 22:56
Some JS cookie helper methods which can be useful in SP2013 apps.
window.COB = window.COB || {};
window.COB.cookieHandler = {
setCookie: function (cookieName, cookieValue, cookieLifetimeDays, cookiePath) {
var expiryDate = new Date();
expiryDate.setDate(expiryDate.getDate() + cookieLifetimeDays);
var cookieContents = escape(cookieValue) + ((cookieLifetimeDays === null) ? "" : "; expires=" + expiryDate.toUTCString()) + ((cookiePath === null) ? "" : "; path=" + cookiePath);
document.cookie = cookieName + "=" + cookieContents;
},
getCookie: function (cookieName) {
@chrisobriensp
chrisobriensp / SP2013App_SPHostUrl_BugWorkaround.js
Created January 28, 2013 23:01
Shows a possible way of working around the apparent bug in SP2013 apps, where the SPHostUrl parameter value is incorrect on subsequent navigation to the app default page.
function sharePointReady() {
// retrieve passed app web/host web URLs..
if (_spPageContextInfo != undefined) {
// allow this code to be used in an app part page..
appweburl = _spPageContextInfo.webAbsoluteUrl;
if ((document.referrer !== "") && (!document.referrer.toLowerCase().startsWith(appweburl.toLowerCase()) && ($.getUrlVar("SPHostUrl")))) {
// we came from outside app web and are being passed SPHostUrl, so this should be the correct value - let's
// store it in a cookie against this path..
hostweburl = decodeURIComponent($.getUrlVar("SPHostUrl"));
@chrisobriensp
chrisobriensp / Item_Picture3Lines_COB_Step1.js
Last active December 14, 2015 00:39
Custom Display Template for SharePoint 2013 Content Search web part - step 1
function ULSwTY() { var o = new Object; o.ULSTeamName = "Search Server"; o.ULSFileName = "Item_Picture3Lines_COB.js"; return o; }
function DisplayTemplate_4e6d0eb6ab864223bd62f9110512a87e(ctx) {
ULSwTY:;
var ms_outHtml = [];
var cachePreviousTemplateData = ctx['DisplayTemplateData'];
ctx['DisplayTemplateData'] = new Object();
DisplayTemplate_4e6d0eb6ab864223bd62f9110512a87e.DisplayTemplateData = ctx['DisplayTemplateData'];
ctx['DisplayTemplateData']['TemplateUrl'] = '~sitecollection\u002f_catalogs\u002fmasterpage\u002fDisplay Templates\u002fContent Web Parts\u002fItem_Picture3Lines_COB.js';
ctx['DisplayTemplateData']['TemplateType'] = 'Item';
@chrisobriensp
chrisobriensp / DisplayTemplate_Elements.xml
Last active December 15, 2015 18:48
XML to deploy a custom Display Template (e.g. for Content Search web part) as a Feature.
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="DisplayTemplates" Url="_catalogs/masterpage/Display Templates/Content Web Parts" Path="DisplayTemplates" RootWebOnly="TRUE">
<File Path="CSWP\Item_Picture3lines_COB_blue.js" Url="Item_Picture3lines_COB_blue.js" Type="GhostableInLibrary" Level="Published" ReplaceContent="TRUE">
<Property Name="Title" Type="string" Value="COB - picture on left, 3 lines, blue" />
<Property Name="ContentTypeId" Value="0x0101002039C03B61C64EC4A04F5361F385106603" Type="string"/>
<Property Name="MasterPageDescription" Type="string" Value="This Item Display Template shows items with a blue background. There is a 100x100 picture of the item on the left. The title and the default item description will display to the right of the picture with an additional line that is available for a custom managed property." />
<Property Name="ManagedPropertyMapping" Type="string" Value="'Picture URL'{Pic
@chrisobriensp
chrisobriensp / AllUsersWebPart_CSWP_DisplayTemplate.xml
Created April 3, 2013 23:01
XML to provision a Content Search web part onto a page in SharePoint 2013 - currently fails to link to Display Template ("ItemTemplateId" property).
<AllUsersWebPart WebPartOrder="0" WebPartZoneID="Header" ID="g_39974cac_a894_49c7_ba69_a39aa28c0013">
<![CDATA[<webParts>
<webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
<metaData>
<type name="Microsoft.Office.Server.Search.WebControls.ContentBySearchWebPart, Microsoft.Office.Server.Search, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
<importErrorMessage>Cannot import this Web Part.</importErrorMessage>
</metaData>
<data>
<properties>
<property name="StatesJson" type="string">{}</property>
@chrisobriensp
chrisobriensp / HostWeb_FileProvisioning_App.js
Last active August 25, 2017 04:50
Shows JSOM code to provision a file to the host web from an app (assuming it is provisioned to app web initially). In this case it is a master page, and if successful we also set it to be the master page used on the host web.
'use strict';
window.COB = window.COB || {};
window.COB.HostWebApp = function() {
var hostWebUrl,
appWebUrl,
hostWebContext,
destinationServerRelativeUrl,
destinationFileName,
@chrisobriensp
chrisobriensp / HostWeb_FieldAndContentTypeProvisioning.js
Created June 20, 2013 13:31
Shows JSOM code to provision fields (site columns) and content types, and also add a site column to the content type.
/// <reference path="jquery-1.7.1.js" />
/// <reference name="MicrosoftAjax.js" />
/// <reference path="~/_layouts/15/init.js" />
/// <reference path="~/_layouts/15/SP.Core.js" />
/// <reference path="~/_layouts/15/SP.Runtime.js" />
/// <reference path="~/_layouts/15/SP.UI.Dialog.js" />
/// <reference path="~/_layouts/15/SP.js" />
'use strict';
@chrisobriensp
chrisobriensp / RemoteEventReceiver_Elements.xml
Last active December 19, 2015 06:39
Declaration of remote event receiver running in Azure Websites.
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Receivers ListTemplateId="100">
<Receiver>
<Name>RemoteEventReceiver1ItemAdding</Name>
<Type>ItemAdding</Type>
<SequenceNumber>10000</SequenceNumber>
<Url>~remoteAppUrl/RemoteEventReceiver1.svc</Url>
</Receiver>
</Receivers>
@chrisobriensp
chrisobriensp / RemoteEventReceiver_AppManifest.xml
Last active December 19, 2015 06:39
App manifest for provider-hosted app which uses remote event receivers.
<?xml version="1.0" encoding="utf-8" ?>
<!--Created:cb85b80c-f585-40ff-8bfc-12ff4d0e34a9-->
<App xmlns="http://schemas.microsoft.com/sharepoint/2012/app/manifest"
Name="BasicDataOperations"
ProductID="{13823eb3-b415-4c21-9884-e67182aa12ce}"
Version="1.0.0.0"
SharePointMinVersion="15.0.0.0"
>
<Properties>
<Title>BasicDataOperations</Title>