Author Archives: Tony Phillips

SharePoint Consultancy and Services

Cloud Design Box

A few months ago, I started a new SharePoint consultancy business. I will continue to add blog posts here but you can contact me directly for any of the following Microsoft SharePoint and Office 365 services by clicking here:

  • Responsive design and branding
  • Site architecture planning and implementation
  • Workflow and consultancy services
  • SharePoint upgrades
  • Office 365 configuration
  • SharePoint Support
  • Scripting and client object model solutions

We provide these services for education and for business. Please visit the website for more information www.clouddesignbox.co.uk

How to add the content query web part to a page layout in SharePoint 2013 and SharePoint Online

Content queries in page layouts can be quite useful when wanting to generate your own navigation based on page content type. There isn’t a straight forward way to adding these into your current page layouts so I thought it would be useful to share this method.

Open Design Manager from the menu.

SharePoint menu

Select “Edit Page Layouts” and create a new temporary page layout (as shown below).

SharePoint Design Manager

Select “Conversion successful” to go to the preview page. In the top right select “Snippets” to open up the snippet code generator.

Code Snippet

Select “Other Web Parts” drop down menu and click “Content Query”.

Content Query

Configure the web part including the appearance, title and queries. Select the update button to generate the custom code.

Web Part Properties

Copy the custom code generated, this code needs to be pasted into the HTML version of the temporary page layout via SharePoint Designer 2013. Once this code has been copied into the page layout HTML, in this case testttt.html, save the file.

SharePoint will then automatically convert this code to aspx in the file testttt.aspx. Open this file to grab the content query code which can be used in any page layout.

Page layout with content query

Of course you can use the design manager to create your actual page layout (rather than just using it to convert code) but many people find this restrictive and already have good page layouts ready to deploy.

If you require any help or training, check out my consultancy company Cloud Design Box which provides this and other services for SharePoint on-premises and Office 365.

Looping through all subsites in SharePoint Online

SharePoint Online requires use of the Client Object model when modifying the site via PowerShell due to there being no backend server exposed in Office 365. Users with previous experience of using JavaScript Client Object model will find this a familiar method.

In the example below, the Powershell iterates through all subsites (and subsites of subsites) in a site collection or root site. This could be used for disabling a web scoped feature or automating site modification.

First of all, the variables are initiated including the path to the relevant DLLs.

#connection variables and reference DLL
$username = "user@onmicrosoft.com"
$password = "Password123"
$SiteCollectionUrl = "https://tonyishere.sharepoint.com"
Add-Type -Path "c:\Microsoft.SharePoint.Client.dll"

A new object for the client context requires creating, this can be done in a reusable function as shown below.

# Generate ClientContext function so we can reuse
function GetClientContext($SiteCollectionUrl, $username, $password) {
     $securePassword = ConvertTo-SecureString $password -AsPlainText -Force
     $context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteCollectionUrl) 
     $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $securePassword) 
     $context.Credentials = $credentials
     return $context
}

The following function has a nested call to call itself, this enables it to iterate through subsites of subsites. Without the nested function call, it would only cover a single subsite depth. The function writes the url of the site to the screen but this could be replaced with more complex functionality such as enabling a feature or creating a list item.

# function to loop through subsites
function catchsubsites ($subsiteurl){
	$clientContext = GetClientContext $subsiteurl $username $password
	$rootWeb = $clientContext.Web
	$childWebs = $rootWeb.Webs
	$clientContext.Load($rootWeb)
	$clientContext.Load($childWebs)
	$clientContext.ExecuteQuery()
	#do something on top level site
	write-host $rootWeb.url -ForegroundColor Yellow
	foreach ($childWeb in $childWebs)
	{
		#do something for each subsite
		write-host $childWeb.url -ForegroundColor Yellow
		#see if there are any subsites beneath this and loop all of them too
		catchsubsites $childWeb.url
	}
}

Finally the function is called to kick off the whole process of looping through the site.

#Finally run the function to get it all started!
catchsubsites $SiteCollectionUrl

This example could be refined so that it doesn’t authenticate at every request but it does show how simple it can be to create the complex PowerShell scripts that we are all used to using on SharePoint on-premises in the cloud version of Microsoft’s Office 365 SharePoint Online.

Update: Code updated 01/10/2016, fixed variable in loop and added section to run code for parent site

Create a simple helpdesk in SharePoint

Below is a quick tutorial on how to create a simple helpdesk/support log in SharePoint online (Office 365) or using the on-premises SharePoint 2013 release. It uses out-of-the-box functionality to create a simple system for users to log and track support issues.

The steps required to create the help desk are:

  • Create a custom list
  • Add additional columns
  • Create list views
  • Create a new item form
  • Set list permissions
  • Configure Alerts
  • Create a notify workflow

Create a custom list
Select “Add an App” from the SharePoint menu

Office 365 menu

Select “Custom List”

SharePoint 2013 App

Give the App a Name

SharePoint 2013 App Custom List
Create additional columns
In the list settings, create some additional columns:

Description (multiple lines of text)*

Status (choice with the options: New, In Progress, Resolution Offered, Closed)*+

Resolution (multiple lines of text)

* Set column as required – force users to enter a value

+ Set default value to “New”

SharePoint App Columns
Create list views
On the list page, select “Create View”

SharePoint 2013 list view

Create a new view based on All Items called “My Open Calls”. This is the default end user view to review their open calls.

Select the following columns:

Title (linked to item)

Status

Created

Uncheck any other columns. Add a filter to show items created by the user and items that do not have the status “Closed”.

Filter 365 list view

Create another view called “My Closed Calls”. Display the following columns:

Title

Status

Filter by the user and items that have the status “Closed”.

Filter SharePoint 2013 View

You may also want to sort these items by newest first to make it easier for the end user to see recently closed items.

Create another view called “All Resolved Calls”. Display the following columns:

Title

Description

Resolution

Created By

Created

This time only add a filter to show items with the status “Closed”.

Filter View

Create another view called “All Open Calls”. Display the following columns:

Title

Description

Status

Resolution

Created

Created By

This time only add a filter to show items without the status “Closed”.

Filter 365

The views “All Open Calls” and “All Resolved Calls” will be used by the resolution team to manage logged issues. The other views will be used by the end user to track their own open issues.

Permission List
At this stage, users with contribute access can add and edit all the logged incidents. This needs to be locked down so users can only edit their own items. To do this, select “Advanced Settings” from the List Settings page.

List Settings

Lock down the Item-level Permissions so that users can only read and edit their own items.

Item Level Permission

Users will Full Control on the list will have access to see and edit all of the items despite the settings above.

Create a new form
Open the site in SharePoint Designer 2013. Using the Site Objects Navigation, find the “Lists and Library” category and select the list.

SharePoint Designer 2013

Create a new Form for the list by selecting “New” in the Forms section.

New Form Advanced Mode

Give the form a new name and select the “New item form” type. Set this as the default form for the selected type.

Form Settings

Right click on the new form and select “Edit in Advanced Mode”

Edit in advanced mode

Locate the table rows in the HTML for the Status and Resolution. Remove these including the start and end tr tag. This will remove the columns from the new form. Save the form, this should now apply to any new items added to the list.

New Form

Set up alerts and workflows
The support team should sign up for alerts on the list so that they are notified when a new issue is added or updated. A simple workflow can be added to the list to notify the end user when their issue has been updated. I will write a blog post on how to do this soon.

Design
Adding icons to a SharePoint page to point directly to the views will make it easier to navigate for the end user and much more attractive to use

List subsites using the JavaScript client object model in SharePoint 2013

SharePoint Office 365 Site Creation JavaScript

To do this, use the script editor web part or the page viewer web part (and put the HTML file in a document library).

To start off, setup the HTML to include jQuery and sp.js (see below).

SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function () {
 //alert('loaded');
});

JQuery functions are used to populate HTML containers on the page.

<div id="tonycontent">
	<!-- Dashboard -->
	<div id="tonydashboard" class="tonycontenttable">
	</div>
</div>

The first function loads the current site. The get_current function returns the current context of the user from which the subsites can be retrieved (see below).

function getSubWebs(){
	clientContext = new SP.ClientContext.get_current();
	web = clientContext.get_web();
    	webCollection = web.getSubwebsForCurrentUser(null);
    	clientContext.load(webCollection);
    	clientContext.executeQueryAsync(onGetSubwebsSuccess, onGetSubwebsFail);
}

If the query is successful it will load the onGetSubwebsSuccess function, otherwise it will run onGetSubwebsFail function.

In the success function, the webCollection variable is looped through to retrieve the URL and the title of each subsite. JQuery functions are then used to append the HTML containers.

function onGetSubwebsSuccess(sender, args){
	jQuery("#tonydashboard").empty();
	var html4 ="<div class='tonycontenttablerow'><div class='tonycontenttabletitle'>Site Name</div><div class='tonycontenttabletitle'>Site URL</div></div>";
	jQuery("#tonydashboard").append(html4);
    var webEnumerator = webCollection.getEnumerator();	
    while (webEnumerator.moveNext()){
        var web = webEnumerator.get_current();
		var webtitle = web.get_title();
		var weburl = web.get_serverRelativeUrl();
        var html3="<div class='tonycontenttablerow'><div class='tonycontenttablecolumn'>" + webtitle + "</div><div class='tonycontenttablecolumn'>" + weburl + "</div></div>";
		jQuery("#tonydashboard").append(html3);
    }
}

Download the full code here

The client object model can also be used to create subsites from templates, permission sites, create lists and much more! This method works on both 365 SharePoint Online and SharePoint 2010 and SharePoint 2013 on-premises.

SharePoint 2013 JavaScript Client Object Model

Using document templates in SharePoint (365 and on premise)

Document Library Templates

Each content type in a document library can be assigned an individual document templates. In the document library below, two different content types have been added, each with a different template.

Tony is here

To edit the word templates, open the site in SharePoint designer 2013.

SharePoint Designer

Open the document library.

SharePoint Designer

In the content types section, open the content type (in this case it is called Policy).

Content Types

In the ribbon select “Edit Document Template”.

Edit Template

This will allow you to create a dotx document which will be the template for this particular content type in this library. Once the template has been saved, it will be available as the main template for the content type.

Select Document

When users create a document using the Policy content type from the new menu, it will prompt them to enter a name for the new document.

Name Document

Please note that currently, the new templates will only open in Office Web Apps (online) if using Internet Explorer. Other browsers will prompt to open in the client application.

Office web Apps online

JavaScript Client Object Model in SharePoint 2013

SharePoint 2013 has a new and more complete JavaScript Client Object Model API. Some of the additional functionality is using social networking.

Using the JS COM, followers can be pulled from SharePoint for the current user or a specific user. This might be used for creating a new social networking interface

My Followers

First load JQuery and the SharePoint 2013 JavaScript functions. The JavaScript functions are loaded on the page so it is just a case of waiting for specific functions to be loaded before the script will work correctly (see below):

SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function () {
	SP.SOD.executeFunc('userprofile', 'SP.UserProfiles', function () {
		tonyishereGetUserProfileProperties();
	});
});

Once the functions are loaded, the People manager object can be created. The example below was taken from the Micrsoft site and modified, this is a great resource if you are starting out with the client object model.

http://msdn.microsoft.com/en-us/library/office/jj679673.aspx

function tonyishereGetUserProfileProperties() {
    // Get the current client context.
    var clientContext = SP.ClientContext.get_current();
    // Get the PeopleManager instance.
    var peopleManager = new SP.UserProfiles.PeopleManager(clientContext);
    // Get the people who are following the current user.
    Followers = peopleManager.getMyFollowers();
    clientContext.load(Followers);
    // Send the request to the server.
    clientContext.executeQueryAsync(displayFollowers, requestFailed)
}

Once the object has been loaded successfully, functions can be run to pull out the required data. In the example below, the data is stored in a string which is then displayed as HTML in a div using JQuery.

function displayFollowers() {
    var results = Followers.getEnumerator();
	var myFollowers = "Followers<br />";
    while (results.moveNext()) {
    var person = results.get_current();
		myFollowers = myFollowers + "<br />" + person.get_displayName();
    }
	jQuery("#MyFollowers").html(myFollowers);
}

The script was added to the page without the use of Visual Studio or SharePoint Designer 2013. The script was inserted using the Script Editor web part. This web part runs client side code such as HTML and JavaScript.

Script Editor

The same methods can be used to pull out a whole host of data from the social aspects of SharePoint 2013 including the profile picture, display name, hash tags and trending topics.

Profile web part

Troubleshooting Office Web App Farm Installations

New functionality in Microsoft Office Web Apps is the preview feature in search (see below). Setting up a separate farm for Office Web Apps is a great way to improve performance and make a scalable solution but it can bring up some new technical challenges. A couple of the most common issues are listed below.

Web Apps Search Preview

Do the internal and external URLs of the Web Apps Server resolve from the SharePoint server?

Test: https://webapps.contoso.com/hosting/discovery
Should return XML without certificate error

Test: https://WebAppServer01.contoso.com/hosting/discovery
Should return XML without certificate error

Certificate Error?

When setting up the web apps farm, a SAN certificate needs to be specified with both the internal URL and the external URL (see below). Wildcard or single host certificates will not work.

SAN Certificate
404 not found?

Both the SharePoint and Web App server need to see each other. Make sure that internal DNS is setup for the external web app address. Run ipconfig /flushdns on the SharePoint server. The SharePoint server needs to resolve both addresses internally.

The Web Apps server also needs to have an entry for the SharePoint site URL. Ensure that the SharePoint site has an internal DNS entry and flush the DNS on the web apps server. Browse to the SharePoint site on the web apps server to ensure that it can see the site without any certificate errors.

How to enable blob cache for SharePoint 2013 image renditions

One of the new features of SharePoint 2013 is the image renditions. When configuring this you may find the following error:

The blob cache is not enabled in this web application. Image renditions will not be generated until the blob cache is enabled. For information on turning on the blob cache, please review the product documentation.

Image Renditions Error SharePoint 2013

Resolution:

Open the web.config file for the web application in a text editor. Search for “blobcache location”.

Inside this tag, change the “enabled” attribute from false to true (see below). This will enable blob cache on the server to enable SharePoint 2013 image renditions.

 
<BlobCache location="C:\BlobCache\14" path="\.(gif|jpg|jpeg|jpe|jfif|bmp|dib|tif|tiff|themedbmp|themedcss|themedgif|themedjpg|themedpng|ico|png|wdp|hdp|css|js|asf|avi|flv|m4v|mov|mp3|mp4|mpeg|mpg|rm|rmvb|wma|wmv|ogg|ogv|oga|webm|xap)$" maxSize="10" enabled="true" />

Save the web.config file and refresh your browser page. All sorted!

Image Rendition Working in SharePoint 2013