Skip to content

Instantly share code, notes, and snippets.

@sksnips
sksnips / GetListAuthor.cs
Created December 24, 2015 16:46
This example retrieves the author who created a SharePoint list using managed client side object model
using System;
using System.Linq;
using System.Net;
using System.Text;
using System.Xml;
using System.Collections.Generic;
using Microsoft.SharePoint.Client;
namespace spknowledge.csomsamples.GetListAuthor
{
@sksnips
sksnips / getlistauthor-som.cs
Created December 24, 2015 18:15
This snippet used to retrieve the author name of the SharePoint List using Server Object Model
using System;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint;
namespace spknowledge.somexamples.GetListFolder
{
class Program
{
@sksnips
sksnips / getcheckoutstatus-jsom.js
Created December 26, 2015 06:03
This JSOM snippet helps to identify the check-out status of the file in SharePoint library
function getcheckoutStatus(listtitle, itemid) {
var clientContext = SP.ClientContext.get_current();
if (clientContext != undefined && clientContext != null) {
var webSite = clientContext.get_web();
this.list = webSite.get_lists().getByTitle(listtitle);
this.item = list.getItemById(itemid);
this.file = this.item.get_file();
clientContext.load(this.file);
clientContext.executeQueryAsync(Function.createDelegate(this, this.OnLoadSuccess), Function.createDelegate(this, this.OnLoadFailed));
}
@sksnips
sksnips / GetFirstStageRecyclebinItems.cs
Created December 28, 2015 05:31
Retrieves the deleted items from RecycleBin (FirstStage) using CSOM
//CSOM Assembly version - 16.1.4727.1200
//using Microsoft.SharePoint.Client
//GetFirstStageRecyclebinItems(credentials, weburl);
private static void GetFirstStageRecyclebinItems(SharePointOnlineCredentials credentials, string weburl)
{
RecycleBinItemCollection recyclebinItems = null;
using (ClientContext ctx = new ClientContext(weburl))
{
@sksnips
sksnips / tenantsitecollections.cs
Created December 30, 2015 00:56
Retrieves the list of site collections available in SharePoint Online Tenant
//using Microsoft.SharePoint.Client;
//using Microsoft.Online.SharePoint.TenantAdministration;
//string weburl = "https://site-admin.sharepoint.com";
//GetSiteCollections(credentials, weburl);
//This method returns the count of Site Collections available in the tenant
//Also returns thr url of all site collections
private static void GetSiteCollections(SharePointOnlineCredentials credentials, string weburl)
{
@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)
@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 / 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 / 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 / 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))
{