Skip to content

Instantly share code, notes, and snippets.

View vgrem's full-sized avatar
🏠
Working from home

Vadim Gremyachev vgrem

🏠
Working from home
View GitHub Profile
@vgrem
vgrem / approveItem.js
Created June 7, 2014 21:58
Approve list item using JSOM in SharePoint
function approveItem(listId,itemId,comment,success,error) {
var context = SP.ClientContext.get_current();
var list = context.get_web().get_lists().getById(listId);
var item = list.getItemById(itemId);
item.set_item('_ModerationStatus',0);
item.set_item('_ModerationComments',comment);
item.update();
context.executeQueryAsync(
@vgrem
vgrem / Folders-RestSPO.ps1
Last active August 29, 2015 14:05
CRUD operations against SharePoint Folder via SharePoint 2013 REST API
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")
. ".\Invoke-RestSPO.ps1"
<#
.SYNOPSIS
Retieve Folder
.DESCRIPTION
Read Folder operation via SharePoint 2013 REST API
url: http://site url/_api/web/GetFolderByServerRelativeUrl('/Shared Documents')
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")
. ".\Invoke-RestSPO.ps1"
<#
.SYNOPSIS
Retieve Files in Folder
.DESCRIPTION
Read Files operation via SharePoint 2013 REST API
url: http://site url/_api/web/GetFolderByServerRelativeUrl('/Folder Name')/Files
@vgrem
vgrem / ListsClient.cs
Created September 3, 2014 15:06
Client for performing CRUD operations against List resource in SharePoint Online (SPO)
using System;
using System.Net;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace SPORestClient
{
/// <summary>
/// Client for performing CRUD operations against List resource in SharePoint Online (SPO)
/// </summary>
@vgrem
vgrem / EnsureFolder.cs
Last active August 29, 2015 14:06
Ensures the nested folder exists using SharePoint SSOM
using System;
using System.Linq;
using Microsoft.SharePoint;
namespace SharePoint
{
internal static class SPFolderExtensions
{
/// <summary>
/// Ensure SPFolder
@vgrem
vgrem / Invoke-SPRestRequest.ps1
Created September 23, 2014 11:14
Sends an HTTP or HTTPS request to a SharePoint 2010 REST-compliant web service
<#
.Synopsis
Sends an HTTP or HTTPS request to a SharePoint 2010 REST-compliant web service.
.DESCRIPTION
This function sends an HTTP or HTTPS request to a Representational State
Transfer (REST)-compliant ("RESTful") SharePoint Online web service.
.EXAMPLE
Invoke-SPRestMethod -Url "https://contoso.sharepoint.com/_vti_bin/ListData.svc/Projects"
#>
Function Invoke-SPRestRequest()
@vgrem
vgrem / getListProperties.js
Last active August 29, 2015 14:08
Get SP.List property using SharePoint JSOM
function getListProperties(listTitle, OnSuccess,OnError) {
var context = SP.ClientContext.get_current();
var web = context.get_web();
var list = web.get_lists().getByTitle(listTitle);
context.load(web);
context.load(list,'SchemaXml');
context.executeQueryAsync(function(){
function getListAuthor(listTitle,OnSuccess,OnError) {
getListProperties(listTitle,
function(listJson){
var context = SP.ClientContext.get_current();
var listAuthor = context.get_web().getUserById(listJson.Author);
context.load(listAuthor);
context.executeQueryAsync(
function(){
OnSuccess(listAuthor);
},OnError);
@vgrem
vgrem / getListProperties.js
Last active August 29, 2015 14:09
Getting SP.List properties using SharePoint REST
function getJson(url)
{
return $.ajax({
url: url,
type: "GET",
contentType: "application/json;odata=verbose",
headers: {
"Accept": "application/json;odata=verbose"
}
});
@vgrem
vgrem / getListAuthor.js
Created November 9, 2014 11:36
Getting SP.List Author property using SharePoint REST
getListProperties('Discussion Board')
.done(function(properties)
{
console.log('List created by: ' + properties.Author);
})
.fail(
function(error){
console.log(JSON.stringify(error));
});