Archive for the ‘SharePoint Online’ Category

SharePoint – Creating a Rotating Image Banner using JavaScript

April 27, 2015 2 comments

In this post I will show you how easily we can create a Rotating Image banner in SharePoint 2013. (I saw the requirement from

Images are stored in an Images Library (Picture Library)

First you need to place anĀ img tag into the Page. This is the tag which loads Images from Library and cycles images every 5 seconds.

<img id="imageRotator" >

Once this is added, you can use below JavaScript code

	var arrayOfImageObjects = new Array();
	var currentImageIndex = 0;
	function GetImagesAndRotate() {
		var url = "http://siteurl/_api/web/lists/getbytitle('ImageLibrary')/items?$expand=File"
			url: url,
			type: "GET",
			headers: { 
				"accept": "application/json;odata=verbose",
				"content-type": "application/json;odata=verbose",
				"X-RequestDigest": $("#__REQUESTDIGEST").val(),				
			success: function(data){
				var result = data.d.results;
					var image = result[i];
					var imageObject = { };
					imageObject.Name = image.File.Name;
					imageObject.Url = image.File.ServerRelativeUrl;
					imageObject.Width = image.File.ImageWidth;
					imageObject.Height = image.File.ImageHeight;					
			error: function(){
				alert("request failed");
	function NextImage(){		
		if(currentImageIndex < arrayOfImageObjects.length) {
			currentImageIndex = 0;		

Finally you can invoke this using


SharePoint – JSOM Sample for SP.AttachmentCollection.getByFileName Method

Today I found a question in StackExchange.

The OP was asking how to use this method using Client Side Object Model. Since this is not available in MSDN ( I thought of creating it.

Here is the sample – You should change the LISTNAME, ID & FILENAME

var clientContext = SP.ClientContext.get_current();
var list = clientContext.get_web().get_lists().getByTitle("LISTNAME");
var listItem = list.getItemById(ID);
clientContext.executeQueryAsync(Function.createDelegate(this, onSuccess), Function.createDelegate(this, onFailure));

function onSuccess(sender, args) {
	var item = listItem;
	var total = item.get_attachmentFiles().get_count();
	if (total > 0) {
		console.log(total + " file attachments");

function onFailure(sender, args) {

SharePoint Online – Setting up PowerShell

SharePoint global administrator can use the SharePoint Online Management Shell to manage the site and content.

Following are the steps we should do for that

  1. Install Windows Management Framework 3.0 – You can download it from This require a system restart
  2. Install SharePoint Online Management Shell – You can download it from

Once this is done, you can start “SharePoint Online Management Shell” and use following command to connect

Connect-SPOService -Url -credential

After connection, you can execute SPO cmdlets and work remotely.



will retrieve all sites.

Take a look at this to find the list of supported cmdlets

Categories: Misc, SharePoint Online Tags:

SharePoint 2013 – Hide page title

December 4, 2013 7 comments

Here is a snippet which can be used to hide page title. All you need to do is edit the master page and place the script inside head tag

<script type="text/javascript">
	function hidePageTitle() {
		var elem = document.getElementById('pageTitle'); = 'block';


SharePoint 2013 – Open folder in new window

December 3, 2013 Leave a comment

I found a question related to opening folder in new window.

The solution is to override HandleFolder method and use the script below

function HandleFolder(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) {
	var parts = new Array();
        parts = c.toLowerCase().split('%2f');
        c = c.replace('SitePages/Home.aspx',parts[1]);;
	return false;

Edit page, add new script editor webpart and use the script.

SharePoint 2013 – Document Library – Download a copy button

November 29, 2013 8 comments

I found a question in technet forum, the user was asking on How to add “DOWNLOAD A COPY” button in document library COLUMN?

And to answer this question, I did a bit of research and came up with below solution

First step is to add a new column to the document library. I named it as “Download a copy”


Ensure to add the new column as the last column in the View.

Now go back to the view, then edit page. Now add a new Script Editor webpart and paste below code

<script type="text/javascript">
function runAfterEverythingElse(){
var elementArray = document.getElementsByClassName("ms-vb-lastCell");
var idArray = document.getElementsByClassName("ms-listlink");
for(var i = 0; i < elementArray.length; i++)
	elementArray[i].innerHTML = '<a unselectable="on" href="javascript:;" onclick="\''+ idArray[i]['href'] + '\')" class="ms-cui-ctl-large " aria-describedby="Ribbon.Documents.Copies.Download_ToolTip" mscui:controltype="Button" role="button" id="Ribbon.Documents.Copies.Download-Large"><span unselectable="on" class="ms-cui-ctl-largeIconContainer"><span unselectable="on" class=" ms-cui-img-32by32 ms-cui-img-cont-float"><img unselectable="on" alt="" src="/_layouts/15/1033/images/formatmap32x32.png?rev=31" style="top: -409px; left: -35px;"></span></span><span unselectable="on" class="ms-cui-ctl-largelabel">Download a<br>Copy</span></a>';

Click Ok, and stop editing the page. Final result


SharePoint 2013 – Specialized Search Experience

November 28, 2013 Leave a comment

SharePoint 2013 Enterprise search gives out a specialized search experience.


For example, “Everything” will searches across all crawled contents while “People” searches only data related to people etc. In SharePoint 2013 we can customize this pretty quickly. For example, we can easily create a search experience for Microsoft Word documents.

Creating a specialized search experience is a two step process, the first step is to create a Result Source and the next step is to use Search Result webpart.

Creating Result Source

Open site settings and click on Result Sources

Click on New Result Source

Fill following details
Now save and close the window.

Creating Search Results

First create a new Page and name is word-results.aspx


Edit Search Results webpart using the context menu. And click on Change Query


This will bring up the query builder window. Select “Word Results” from Select Query dropdown


Click “Ok” and close the query builder tool. Apply and close the webpart properties pane. The page is ready which only returns search results containing word documents.

Next step is to edit the search experience links. For that, open site settings and click on search settings


Click on Add Link and fill in the details


Click OK and go to search center, now you can see your specialized search experience in action.


SharePoint 2013 – List Validation

November 26, 2013 2 comments

One of my friend recently asked me how to apply list validation in SharePoint 2013. I explained him and thought of documenting it so others can use it for reference.

To start with I am trying to enforce the following requirement

There is a list with 3 choice columns “A”, “B”, and “C”. In any of these columns a value = “None” is not allowed.


Open list setting


Click on Validation Settings


Now you can apply formula and a message which will appear if validation fails


Formula uses the IF condition for validation. The general syntax is IF(condition, true case, false case).
First we will check if column “A” is not equal to “None”, then only go and validate “B”. The same logic is applied for validating “B” and then “C”


SharePoint Sandbox Solution – Page Redirect

May 14, 2013 2 comments

Redirecting to a new page from a sandbox solution is a big challenge. But customers won’t agree and eventually we need to find a workaround to achieve this.

The best option is to add a literal control in the webpart

<asp:Literal ID="litRedirect" runat="server" />

From codebehind we can redirect using below code

litRedirect.Text = "<script type='text/javascript'>window.location = '';</script>";