Posts

Showing posts from May, 2015

Enable SP.JS in publishing sites for SP 2013

Hi, In my previous post , I have explained the way to add CSOM on master page of any kind of site. But later on when testing same code with publishing site, I realized that sp.js is not loaded on publishing site by default. So in this post I will discuss how to enable sp.js in Publishing Pages in SharePoint 2013. As the SharePoint uses minimal download strategy it prevents the page to have sp.js when published but the point to note is when you open your ribbon bar (edit or unpublished state) sp.js  script gets loaded in your page . Note : SharePoint loads scripts on Demand So to solve this we can do like this : Add a script editor webpart in your page and in script tags just add the following code snippet: SP.SOD.executeFunc('sp.js', 'SP.ClientContext', alert('I have loaded the sp.js script.')); Where instead of alert method you can use any JS method and will be executed after sp.js is loaded. Happy SharePointing :).

SharePoint CSOM for beginners: Get Current User details

Image
Hi Guys, This blog is targeted to developers who are novice to the client side object model in SharePoint. SharePoint apps by default provides a basic stub for getting user details inside app. But sometimes it is required to add client side code in simple script file to get user information. I hope this information will also be helpful starters of client side object model. Pre-requisites: 1) Any version of SharePoint installed: SP 2013, SP 2010 or SP Online 2) A web application and a root site collection inside it. It does not matter whether site is team site or any other type of site.(Note: In case of publishing site you need to enable sp.js file loading ). 3) SharePoint Designer installed. Step I : Create a custom script file A script file is required in order to place CSOM code to be executed. Well, here depending upon usability user can chooses any one of these two locations to create this file: - List or Style library : It will be hard to update script file if it is placed under s