Skip to content

Instantly share code, notes, and snippets.

@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
}
@tiagoduarte
tiagoduarte / powershell-starter-script.ps1
Created September 24, 2016 13:26
powershell starter script
#[summary goes here]
#by [author goes here] @ [date goes here]
#[author URL / email]
clear-host
###################################### FUNCTIONS ##############################
#if the context is not administrator, stop the script and start a new shell
function EnsureAdmin($invocation)
@tiagoduarte
tiagoduarte / show-ribbon.js
Created September 24, 2016 13:19
make sharepoint ribbon reappear after being hidden from page customization
function showRibbonOnCustomizedPages()
{
if(window.location.href.contains("/Forms/AllItems.aspx"))
{
//console.log("library page");
var listViews = $('.ms-listviewtable');
if(listViews.length === 1)
{
//console.log('only one view found');
@tiagoduarte
tiagoduarte / umbracoprojectguids.config
Created September 24, 2016 13:15
umbraco project guids tag
<projecttypeguids></projecttypeguids>