Archive

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 http://sharepoint.stackexchange.com/a/139738/34350)

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"
		
		jQuery.ajax({
			url: url,
			type: "GET",
			headers: { 
				"X-HTTP-Method":"MERGE",
				"accept": "application/json;odata=verbose",
				"content-type": "application/json;odata=verbose",
				"X-RequestDigest": $("#__REQUESTDIGEST").val(),				
			},
			success: function(data){
				var result = data.d.results;
				for(i=0;i<result.length;i++){
					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;					
					arrayOfImageObjects.push(imageObject);
				}				
				setTimeout(NextImage,5000);
			},
			error: function(){
				alert("request failed");
			}
		});
	}
	
	function NextImage(){		
		if(currentImageIndex < arrayOfImageObjects.length) {
			jQuery('#imageRotator').attr('src',arrayOfImageObjects[currentImageIndex].Url);
			currentImageIndex++;
		}
		else
			currentImageIndex = 0;		
		setTimeout(NextImage,5000);
	}

Finally you can invoke this using

	jQuery(document).ready(function(){
		GetImagesAndRotate();
	});
Advertisements

SharePoint – JSOM Sample for SP.AttachmentCollection.getByFileName Method

Today I found a question in StackExchange.

http://sharepoint.stackexchange.com/questions/136304/fetch-list-item-attachment-by-name

The OP was asking how to use this method using Client Side Object Model. Since this is not available in MSDN (https://msdn.microsoft.com/en-us/library/office/jj245502.aspx) 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.load(listItem);
clientContext.load(listItem.get_attachmentFiles().getByFileName("FILENAME"));
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) {
	//failed
}

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 http://go.microsoft.com/fwlink/p/?LinkID=244693. This require a system restart
  2. Install SharePoint Online Management Shell – You can download it from http://go.microsoft.com/fwlink/p/?LinkId=255251

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

Connect-SPOService -Url https://tenant-admin.sharepoint.com -credential admin@tenant.com

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

Example:

Get-SPOSite

will retrieve all sites.

Take a look at this http://technet.microsoft.com/en-us/library/cb90889b-9c1e-4cec-ab0f-774be623022f(v=office.15) 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');
		elem.style.display = 'block';
	}

	_spBodyOnLoadFunctionNames.push("hidePageTitle"); 
</script>

SharePoint 2013 – Open folder in new window

December 3, 2013 Leave a comment

I found a question related to opening folder in new window.
http://social.msdn.microsoft.com/Forums/vstudio/en-US/6fb8e8e7-c3f8-4df9-9ecf-cf48851dc1c0/open-links-from-folders-in-document-libraries-from-a-new-window?forum=sharepointgeneral

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]);
	window.open(c);
	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”

D1

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="window.open(\''+ 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>';
}  
}
_spBodyOnLoadFunctionNames.push("runAfterEverythingElse");  
</script>

Click Ok, and stop editing the page. Final result

D1

SharePoint 2013 – Specialized Search Experience

November 28, 2013 Leave a comment

SharePoint 2013 Enterprise search gives out a specialized search experience.

S1

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
S2

Click on New Result Source
S3

Fill following details
S4
Now save and close the window.

Creating Search Results

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

S5

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

S6

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

S7

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

S8

Click on Add Link and fill in the details

S9

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

S91