Skip to content

Instantly share code, notes, and snippets.

@tiagoduarte
tiagoduarte / form.ie9fix.js
Last active June 30, 2023 14:58
add sharepoint 2010 support for IE10+ (form fix)
//the form.js functions don't play well in IE9 mode
//lets override and fix them
//console.log("loading form.ie9fix.js");
function RTE_GetEditorInstanceVariables(strBaseElementID)
{ULS1Lu:;
if (parent.g_oExtendedRichTextSupport !=null)
{
@tiagoduarte
tiagoduarte / tamper_monkey_spdevtools.js
Last active June 30, 2023 14:57
Adds new buttons near the ribbon for typical SharePoint actions
// ==UserScript==
// @name SharePoint Dev Tools
// @namespace TiagoDuarte
// @description Adds new buttons near the ribbon for typical SharePoint actions
// @version 3.7
// @grant none
// @match https://*.sharepoint.com/*
// ==/UserScript==
/*
@tiagoduarte
tiagoduarte / Parse-XmlFile.ps1
Last active June 24, 2021 08:30
PowerShell snippet to parse an XML file, and retrieve elements, attributes and inner values
param(
#provide the path for the input xml document
$xmlPath = "C:\temp\tiles-list-elements.xml",
#embed xml (for demo purposes)
$xmlContent = '
<Data>
<Rows>
<Row>
@tiagoduarte
tiagoduarte / Unlock-File.inc
Last active September 7, 2020 16:20
Release SharePoint file lock through html+js
<!--
SharePoint document lock release script
Tiago Duarte
Based on code from Peter Holpar,
https://pholpar.wordpress.com/2014/04/07/how-to-use-javascript-to-delete-short-term-locks-from-documents-opened-from-sharepoint/
Page URL:
/Pages/UnlockFile.aspx
@tiagoduarte
tiagoduarte / Release-File.cs
Last active September 7, 2020 16:08
Release SharePoint document lock through server side code (C#)
SPList list = web.Lists[txtListTitle.Text];
SPListItem item = list.GetItemById(int.Parse(txtItemID.Text));
SPFile file = item.File;
if (file.LockType == SPFile.SPLockType.None)
{
txtOutput.Text = "File is not locked";
}
else
{
int lockUserID = file.LockedByUser.ID;
@tiagoduarte
tiagoduarte / Release-File.ps1
Last active September 7, 2020 15:20
Release SharePoint file lock using PowerShell
param(
$webUrl = "http://demosite",
$listTitle = "testlib",
$itemID = 183
)
clear-host
$web = Get-SPWeb $webUrl
$list = $web.Lists[$listTitle]
//dlls in C:\Program Files (x86)\Microsoft Visual Studio 12.0\Visual Studio Tools for Office\PIA\Office15
using Microsoft.Office.Interop.Word;
using Microsoft.Office.Core;
Application wordApp = null;
try
{
//open a new word process
wordApp = new Application();
@tiagoduarte
tiagoduarte / UnlockFile..html
Created April 17, 2018 21:47
Check for document lock and release the lock
<div id="locked-doc">
<p>
<label>Document URL</label>
<br/>
<input id="docUrl" type="text" value="http://" style="width:500px" />
</p>
<p>
<label>Website URL</label>
@tiagoduarte
tiagoduarte / Enable-SPDesigner.ps1
Created August 29, 2017 20:04
SharePoint Designer in Office 365
#params
$username = "admin@contoso.onmicrosoft.com"
$password = "myPWD"
$url = "https://contoso.sharepoint.com"
$adminUrl = "https://contoso-admin.sharepoint.com"
$spd = 0#0-deny disabled; 1-deny enabled
#connect to SPO
$securePassword = ConvertTo-SecureString $password -AsPlainText -force
$credential = New-Object System.Management.Automation.PsCredential($username, $securePassword)
//check if page is in edit mode through page form mode
if (Microsoft.SharePoint.SPContext.Current.FormContext.FormMode == SPControlMode.Display)
{
// your code to support display mode
}
else if(Microsoft.SharePoint.SPContext.Current.FormContext.FormMode = SPControlMode.Edit)
{
// your code to support edit mode
}