Skip to content

Instantly share code, notes, and snippets.

View durgesh97025's full-sized avatar

Rahul Gupta durgesh97025

View GitHub Profile
@durgesh97025
durgesh97025 / EmailFrmSharePoint.js
Created September 20, 2016 11:25
Email using REST API into SharePoint
console.log("Email");
function sendEmail(from, to, body, subject) {
//Get the relative url of the site
var d = $.Deferred();
var siteurl = _spPageContextInfo.webServerRelativeUrl;
var urlTemplate = siteurl + "/_api/SP.Utilities.Utility.SendEmail";
$.ajax({
contentType: 'application/json',
@durgesh97025
durgesh97025 / ProgressDialog.js
Last active July 7, 2023 15:28
Show Progress Bar in Dialog. Useful during ajax operations
$(document).ready(function(){
$("BODY").append('<div id="dialog-message" title="In Progress">\
<div id="progressbar"></div>\
</div>');
});
function ShowDialog() {
$( "#dialog-message" ).dialog({
dialogClass: "no-close",
modal: true
@durgesh97025
durgesh97025 / SPO-FileUpload.js
Created May 31, 2017 12:10
File Upload/Copy from another Http Url in SharePoint Online using REST and jQuery
var SourceList = "SourceList";
var DestinationList = "DestinationList";
$(document).ready(function() {
exec();
$("#myBtn").click(exec);
});
function exec() {
var sourceId = 12;
var sourceAttachmentUrl = _spPageContextInfo.webServerRelativeUrl + "/_api/web/lists/getbytitle('" + SourceList + "')/Items('" + sourceId + "')/Attachmentfiles";
@durgesh97025
durgesh97025 / PermissionManage.js
Created July 27, 2017 11:57
Manage Item Permission, Break, Assign New Role, Remove Existing Role
function PreSaveAction(){
var status = $("[Title~='Status']").val();
if (status == "Final"){
var groupName = "XXX Owners"
PermissionManager.BreakInheritance().then(function(data){
console.log("Permission Inheritance Breaked with roles and groups");
}).fail(function(error){
console.log(error);
}).then(function (){
@durgesh97025
durgesh97025 / Utility.js
Last active March 21, 2023 15:07
Utility for Array, String
String.prototype.replaceAll = function(search, replacement) {
var target = this;
return target.replace(new RegExp(search, 'g'), replacement);
};
Array.prototype.contains = function(v) {
for(var i = 0; i < this.length; i++) {
if(this[i] === v) return true;
}
return false;
$(document).ready(function() {
//SP.SOD.executeOrDelayUntilScriptLoaded(AddCustomUserAction, "sp.js");
SP.SOD.executeOrDelayUntilScriptLoaded(DeleteCustomActions, "sp.js");
});
function DeleteCustomActions() {
var listTitle = "Pension Files";
context = new SP.ClientContext();
var web = context.get_web();
var list = context.get_web().get_lists().getByTitle(listTitle);
@durgesh97025
durgesh97025 / Rest.txt
Last active January 12, 2018 15:29
REST API Example
https://xxx.sharepoint.com/sites/Site/Web/_api/SP.UserProfiles.PeopleManager/GetMyProperties
SharePoint Navigation: _spPageContextInfo.webAbsoluteUrl + '/_api/web/Navigation/GetNodeById(1040)/Children
Quick Launch: _spPageContextInfo.webAbsoluteUrl + '/_api/Web/Navigation/GetNodeById(1031)/Children
QuickLaunch EndPoint :/_api/web/Navigation/QuickLaunch
TopNavigation EndPoint: /_api/web/Navigation/TopNavigationbar
Filters on List/Libraray: /_api/web/lists?$filter=IsCatalog eq false and Hidden eq false and BaseType eq 1&$Select=Title,DocumentTemplateUrl
@durgesh97025
durgesh97025 / CurrentUserPermissionCheck.js
Created October 3, 2017 13:46
Current User Permission Check on SPWeb
$(document).ready(function(){
$.when(checkPermissions()).then(function(isOnlyContributor){
if (isOnlyContributor){
setInterval(HideSiteContents, 1000);
}
});
});
function HideSiteContents(){
console.log($("SPAN:contains('Site contents')").length + " called");
@durgesh97025
durgesh97025 / SPOLogin.cs
Last active May 30, 2017 08:42
SharePoint Online Login using Httpwebrequest via .net 3.5
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Xml.Linq;
using System.IO;
using System.Security;
using System.Xml;
@durgesh97025
durgesh97025 / SPTrick.js
Last active April 25, 2017 07:58
An Js file for SharePoint for speedy development
if (typeof console == "undefined") { this.console = {log: function() {}}; }//If browser doesn't support console.log
//OTO = One Time Object
var rClientContext;//A context OTO used everywhere
var rWeb;//A web OTO used
var rCurrentUser;// A user OTO
$(document).ready(function(){
rClientContext = SP.ClientContext.get_current();
rWeb = rClientContext.get_web();