Skip to content

Instantly share code, notes, and snippets.

@sksnips
sksnips / getwebContentTypes.js
Created March 2, 2016 01:57
This code snippet returns the collection of content types for the website
//Author: Shantha Kumar T
//This getContentTypes method returns only the content types associated to the particular website
//Property used: SP.Web.ContentTypes property (sp.js)
//Supports SharePoint 2013 + and SharePoint Online
function getwebContentTypes(siteurl) {
//var clientContext = SP.ClientContext.get_current(); This line returns the current context
var clientContext = new SP.ClientContext(siteurl); //This line return the context based on the siteurl
oContentTypes = clientContext.get_web().get_contentTypes();
clientContext.load(oContentTypes);
@sksnips
sksnips / getallContentTypes.js
Created February 27, 2016 12:13
Returns the collection of available content types from the Site and its parent sites
//Author: Shantha Kumar T
//This getallContentTypes method returns all content types available in the site collection (site or any parent sites)
//Property used: SP.Web.availableContentTypes property (sp.js)
//Supports SharePoint 2013 + and SharePoint Online
function getallContentTypes() {
var clientContext = SP.ClientContext.get_current();
oContentTypes = clientContext.get_web().get_availableContentTypes();
clientContext.load(oContentTypes);
clientContext.executeQueryAsync(
@sksnips
sksnips / gethiddenLists.js
Created February 27, 2016 02:37
Displays the hidden lists from the current SharePoint site
function gethiddenLists() {
var clientContext = SP.ClientContext.get_current();
oLists = clientContext.get_web().get_lists();
clientContext.load(oLists);
clientContext.executeQueryAsync(
Function.createDelegate(this, function() {
var listsInfo = '';
var listsEnumerator = oLists.getEnumerator();
while (listsEnumerator.moveNext()) {
@sksnips
sksnips / webroledefinitioans-rest-jQuery.html
Created January 7, 2016 14:43
This code snippet returns the collection of role definitions attached to the web
<!-- Author: Shantha Kumar T -->
<!-- HTML snippet returns the collection of role definitions attached to the web -->
<!-- webroledefinitioans-rest-jQuery.html - Role definitins associated to the web -->
<!-- Style required for HTML Snippet -->
<style type="text/css">
.tbl-roles th{ background-color:#ddd; border:2px solid #fff; text-align:left}
.tbl-roles td{ background-color:#eee; border:2px solid #fff;}
.web-heading{ padding:2px;}
</style>
<!--Include jQuery library to perform dynamic html dom manipulation -->
@sksnips
sksnips / getgithubgists.js
Created January 7, 2016 04:41
Retrieve github gist information from browser console
//Author - Shantha Kumar T
//This Javascript snippet to get the gists details from gist web page through browser console
//
var snips = document.getElementsByClassName("gist-snippet");
for(i=0; i< snips.length; i++){
var strvalue = "";
var sniname = snips[i];
var nn = $(sniname).find('.css-truncate-target');
strvalue += "Title: " + $(nn).text().trim()+"\r\n";
strvalue += "Link: "+ location.protocol+"//"+location.hostname+$(nn).parent().attr('href')+"\r\n";
@sksnips
sksnips / GetItemChanges_csom.cs
Created December 31, 2015 17:53
Retrieve all the changes (add, update & delete) occurred on the list item using CSOM
//CSOM Assembly version - 16.1.4727.1200
//using Microsoft.SharePoint.Client;
//using System.Net
//GetItemChanges(credentials, weburl, listtitle, itemid);
//This method returns all the changes (add, update & delete) happened to the list item
private static void GetItemChanges(ICredentials credentials, string weburl, string listTitle, int itemid)
{
using (ClientContext ctx = new ClientContext(weburl))
{
@sksnips
sksnips / GetAllLists.cs
Created December 31, 2015 08:39
Retrieve all the lists and libraries using SharePoint website using CSOM
//using Microsoft.SharePoint.Client;
//using System.Net
//GetAllLists(credentials, weburl);
//This method returns all the lists and libraries from SharePoint website
private static void GetAllLists(ICredentials credentials, string weburl)
{
using (ClientContext ctx = new ClientContext(weburl))
{
ctx.Credentials = credentials;
@sksnips
sksnips / getnonhiddenlists.cs
Created December 31, 2015 08:33
Retrieve the non hidden lists from SharePoint web using CSOM
//using Microsoft.SharePoint.Client;
//using System.Net
//GetNonhiddenLists(credentials, weburl);
//This method returns the lists from the web, which are visible to users
private static void GetNonhiddenLists(ICredentials credentials, string weburl)
{
using (ClientContext ctx = new ClientContext(weburl))
{
ctx.Credentials = credentials;
@sksnips
sksnips / gethiddenlists.cs
Created December 31, 2015 06:55
Retrieve only the hidden lists from SharePoint web using CSOM
//using Microsoft.SharePoint.Client;
//GetHiddenLists(credentials, weburl);
//This method returns the hidden lists from the web
private static void GetHiddenLists(ICredentials credentials, string weburl)
{
using (ClientContext ctx = new ClientContext(weburl))
{
ctx.Credentials = credentials;
Web oweb = ctx.Web;
@sksnips
sksnips / getsitewebscount.cs
Last active December 30, 2015 05:38
Get the count of all websites in sharepoint online sitecollection using CSOM
//using Microsoft.SharePoint.Client;
//using Microsoft.Online.SharePoint.TenantAdministration;
//string weburl = "https://site-admin.sharepoint.com";
//GetSite(credentials, weburl);
//This method returns the site collection object based on the url.
//shows the count of all subwebs available with in SharePoint online Site Collection
//Microsoft.Online.SharePoint.TenantAdministration.SiteProperties.WebsCount property
private static void GetSite(SharePointOnlineCredentials credentials, string weburl)