Nick Hadlee's Blog on SharePoint and Other Occasional Rants…


The First SharePoint Saturday New Zealand
December 19, 2010, 3:13 pm
Filed under: Development, jQuery, SharePoint, SharePoint Saturday, WCF

The first SharePoint Saturday was held in New Zealand on Saturday the 11th of December. I may be a little biased but I think the event was a real success with at least 80-100 people, close to 20 sessions and 17 speakers. A big thanks to all our sponsors, the speakers and also the other organisers. These events are a lot of work to put on so it wouldn’t have been possible without all of these people!

Any of the session slides that have been made available by the speakers are up on the site and we will continue to try and get the rest. Look forward to seeing everyone at next years event…

My session was in the developer stream and built a SharePoint 2010 Alerting solution to show how 1) to build a custom WCF web service that returns JSON, 2) how SP.UI JavaScript namespace is used to interact with the status bar, notifications and modal dialogues and 3) how to call web services from jQuery. The session slides are provide below for anyone that wants them:



An Alternative Method for Using Custom Master Pages with Search in SharePoint 2010
November 6, 2010, 3:41 pm
Filed under: 2010, Cutomisation, Development, Search

Search is a fundamental component of any SharePoint solution and 2010 has some subtle differences and great improvements over its 2007 predecessor:

  1. One improvement are refiners, a new part of the search user interface (formerly known as facets), which allow you refine the search results based on metadata and even better they are extensible
  2. One important difference between 2007 and 2010 is the use of a specific master page in the Search Centres – the minimal.master master page

I’m not a big fan of minimal.master used within the Enterprise Search Centre so that’s the focus of the rest of this post. I’ll propose a way to deliver a fix which basically boils down to not using the minimal.master.

So what’s the problem with minimal.master? Minimal.master is a cut down master page that is new to SharePoint 2010 and used by both Enterprise Search and Office Web Apps. As the Search master page it lacks a few key components available in the other SharePoint 2010 master pages. One fundamental component that is missing in minimal.master are navigation controls.

Minimal.master navigation

The minimal.master lacks most of the usual navigation controls you expect and need.

v4.master navigation

V4.master has the standard top navigation and the new 2010 breadcrumb (hidden inside the folder “up” icon)

Missing the main navigation leaves an Enterprise Search Centre completely isolated from the rest of your SharePoint solution. This is a big limitation – is there are any situation where you shouldn’t be able to get from your search results back to the main and/or other sites?

So why don’t we just change the search master page to one of those other fully featured ones like V4.master? Yeah that was my first idea too. And look what we get…

v4.master applied to search

An Enterprise Search Centre with v4.master applied “floats” the search controls into the breadcrumb navigation.

That wasn’t the result I was expecting and I guess it wasn’t the result most people were expecting if they tried this? This is not a bug but one of those “by design” problems. What you’re seeing is the way the four page layouts of Enterprise Search have been implemented to work specifically with the placeholders in the minimal.master master page. Personally I think this was a poor implementation decision because it uses some of the core placeholders completely differently than the other OOTB SharePoint master pages. Compare V4.master and minimal.master:

Place Holder Use in Minimal.master for search Use in V4.master for…most other things
TitleInBreadCrumb Search controls Breadcrumb navigation controls
SPNavigation Empty in the master page. The search page layouts add page editing controls and the ribbon instead. Page editing controls and the ribbon

The Current Approaches to using a Custom Master Page with Search

We have two options if we want to get rid of the minimal.master from search and put back some of the things we have lost:

  1. Create a custom search master page that is compatible with the search page layouts; or
  2. Modify the search page layouts to make them compatible with an existing custom master page

If you want to do the first option and create a custom master page for search then Randy Drisgill has a really useful and detailed post on how to convert a V4.master (normal) master page to work with the Search Centre.

The second alternative solution is to modify the page layouts to work with your existing custom master page. I first came across the idea via Chris O’Connor and prefer this approach. It’s biggest benefit is you only have to develop/test/maintain one master page which can be used on all your SharePoint sites including the search site!

Unfortunately there is at least one negative side effect to modifying the search page layouts – it makes them unghosted (customized). Unghosted files are generally frowned upon in SharePointland so this approach won’t always suit everyone’s environment/requirements. The biggest problem, and a very valid reason to dislike unghosted files, is once they are customized a copy lives in the content database that is disconnected from the original file system version. This means:

  • These page layouts will not be updated by any changes to the file system versions such as solution (wsp) upgrades and service packs
  • There is a performance penalty (I don’t know how much?) because of the extra database hit required to retrieve the page layout from the content database

Fix Option 2. Explained

There are a few changes that have to be made to all of the search page layouts and your custom master page to implement fix option number 2. To make this as clean as possible I have packaged the changes into a sandbox solution and use a site collection feature (feature activation receiver) to perform all of the heavy lifting in the page layouts:

  1. Change the target placeholder that is used by the search controls by replacing the Id from TitleInBreadCrumb to a custom placeholder ID CustomSearchControls
  2. Remove the SPNavigation placeholder and all its content from the page layouts. This content placeholder is in the v4 master page already so it’s just a duplicate and causes weird ribbon “jumping”
  3. Add some CSS style rules to hide the left navigation areas of the page because search doesn’t use this area of the page

A  big benefit of doing all that work in a feature receiver is the changes are all reverted and the page layouts are reghosted/uncustomized if the feature is deactivated.

Last point – there are changes that must be made to your custom master page to support these modified page layouts. If you don’t add the following placeholder you’ll get an error. The screen shot below shows what needs to be added (the wrapping <div> isn’t strictly necessary but it allows for any custom styling that might also be needed).

Custom PlaceHolder

And once you upload the sandbox solution to the solution gallery, activate the solution/feature and switch your master page to one with the custom placeholder this is what you will see:

Search with custom v4.master applied

This is a good place to stop. The files are up on codeplex and I hope to do a follow up post soon that explains the source code in detail. If you have any ideas on how to improve this or just general comments please hit me up via a blog comment or on twitter. For now here are links to the files:

  1. Sandbox solution with a site collection feature to do the page layout fix-up described in the post – Search.CustomMasterPageAdapter.wsp
  2. Source code of the feature receiver – PageLayoutFixup.cs
  3. Example custom master page which is just v4.master with the custom place holder added – Custom.v4.master


Is it Code? – A Rant, Response and Example of Social Media’s Reach
June 5, 2010, 1:08 pm
Filed under: Cutomisation, Rant

First up a warning! This will appear to be post that has no purpose, meanders a little, and probably has no actual conclusion (also I use all sorts of weird colloquialisms). Appearances are often correct! I didn’t plan to write it but felt compelled to in response to some effort put in Jim (@dullroar) and Raymond (@iwkid). Honourable mentions to Marc (@sympmarc) for his championing of the ‘middle-tier’ (oh brother flames and brimstone await me for the use of that term) and Mark (@mrackley) for tackling a similar question previously. Ok, ok enough with the setup; let’s get on with the show…er post.

I asked what I thought was a fairly innocent question on twitter the other day but is anything ever innocent or innocuous when “thrown” out onto twitterverse or the interwebs? I was trying to validate the use of “codeless” when describing certain types of SharePoint solutions.

nickhadlee Poll: Is #XSL code? In the context of a ‘codeless’ solution :) [Feel free to RT]

Why? Was I trying to deliberately rile people and get into some sort of tit-for-tat twitter banter going? No – absolutely not. The context of the question was aimed at what an end-user might consider code. A typical end-user might not even know what XSL is so the point is possibly moot. Really at the heart of my question was to define what we can call a “no code” SharePoint solution. I am a big fan of using the “no code” moniker and to quote Jim it is "probably more related to business politics rather than technical reality".

So what sort of response did I get? It started off pretty tame.

iwkid RT @nickhadlee: Poll: Is #XSL code? In the context of a ‘codeless’ solution <– I consider it "no-code" in that it is not managed/deployed

kennethprice @nickhadlee I think xsl is within boundaries of codeless solution.

Off I went to bed thinking that was that. 3-0 to the “it’s not code” camp and the “codeless” term can be applied liberally. Hmm that’s what I thought. Overnight Jim and Raymond decided to put pen-to-paper and expand their thoughts on the topic past the 140 character limitations of twitter:

dullroar @nickhadlee @iwkid @sympmarc My (long) answer to the poll: http://ping.fm/aziFn

iwkid @dullroar @nickhadlee @sympmarc @EUSP My response :-) http://www.iwkid.com/blog/Lists/Posts/Post.aspx?ID=82

Not to mention I irked Marc a little. Marc and I chat a bit on the interwebs so I knew the responses were all in good humour (I think…Marc we still talking???):

sympmarc RT @nickhadlee: Poll: Is #XSL code? -> You know my answer to this one. Is English not a language because lots of people speak it?

sympmarc @nickhadlee Is Druidism not a religion because it contains little spiritual duality?

sympmarc @nickhadlee Ok, that’s enough for me. Goodnight, Gracie.

For me Jim’s post pretty clearly sums up why XSL is indeed code. Based on Raymond’s response I think we both now admit our initial NOs were really a bit premature! If you’re still reading then I do congratulate you on persistence…now would be a good time to pull out some high-school-essay-style argument backed up with evidence. Not quite yet – I am quickly going to mention that there were other RTs (that’s a retweet for the twitter uninitiated. Twitter…what you mean that twitter-the-complete waste of time social-media-thing-ma-bob? No I don’t mean that. I mean twitter-the-extended-SharePoint-community-reach-out-tool. Sorry got a little preachy there!). One that I think is worth a mention was from Mark Miller (@EUSP) over at EndUserSharePoint.com. Why? Because if you work in the “no code” world then please check out the site as its one of the better resources for that kind of stuff:

EUSP RT @sympmarc @dullroar: @nickhadlee @iwkid @sympmarc http://ping.fm/aziFn -> Is XSL code? <- Critical discussion for EUSP authors.

Ok so I think I need to wrap this baby up so here is where I stand on the matter.

Do we need a label like “no code” or “codeless”? Does this all really matter or is it just semantics? No I don’t think it matters, not really. It seems easier to brand something ”no code” to make it easier to sell the idea to people that we are using the SharePoint platform more extensively instead of needing to deploy some heavy code-based customisations (By the way I like code – I even write some occasionally!). Are “no code” solutions any less risky or a lower impact option than deployed DLLs?…..NO! That would be a massive half-truth/un-truth/fallacy/plain-old-lie. I have seen Data Views, JavaScript and other “codeless” options bring pages and sites to their knees just as well as any dodgy code can.

Answer the question Nick! Is XSL code? I’d have to say (now) yes it is, thanks again Jim! Do we need a name for this so called “codeless” middle tier? Hmm, probably not but the debate will rage on for a bit yet…bet you a fiver! I think Marc Anderson said it best (not exactly like this but close enough).

“Does it really matter how we get to the solution? It’s satisfying the business requirement that matters most!”

Now I think I have come to the end of my diatribe. I’m not sure if I went anywhere but I at least feel I spent as much time as Jim and Raymond on a response. It has made me think I need to do a post on why I prefer using “codeless” techniques whenever possible but that is definitely a post for another time. Feel free to hit me up on twitter or leave a comment if you find any of this contentious/a further pollution of the internet or whatever. It’s really just the ramblings of a confused and simple mind!



jQuery to Fix ‘Image Web Part’
July 18, 2009, 6:35 pm
Filed under: jQuery, SharePoint

While working on a mini-demo site today I managed to get distracted with a very minor (and irrelevant) component of the site. I felt compelled to find an elegant-ish resolution even though it served no practical purpose for the demo I was building. How often does that happen?

Image Web Part Sizing

The out-of-the-box Image Web Part is great for adding images to a site. Like all Web Parts it has some properties for changing the web parts behavior, but the problem is some of them don’t quite work as you might expect.

The width and height properties are the true target of this this post. Your initial expectation when you set them is the image displayed by the web part will resize to match the settings. This just isn’t how it works – if the image’s physical size is bigger than the Web Part then some ugly scroll-bars appear.

Image Without Resize

Figure 1: Standard ‘Image Web Part’ with the width property set.

Using a little bit of jQuery we can use these properties to apply the settings to our image as well. The following script can be added to the site using the Content Editor Web Part.

 <script type="text/javascript">
$(function(){
 $("img[id^='MSOImageWebPart_']").each(function(){
            var width = $(this).width();
            var parentDiv = $(this).parents("div.ms-WPBody");
            if(width > parentDiv.width()) {
                this.width = parentDiv.width();
            }
        });       
});
</script>  

Dynamically Resized Image

Figure 2: ‘Image Web Part’ that was resized with jQuery

Note: In this example I am only manipulating the width property of the image element. This leaves the browser to calculate the height of the image to keep everything in proportion. The height could be applied as well but then the image can start to look a little distorted):

See my previous post on jQuerywhich has some useful jQuery links including Jan Tielens excellent post on deploying jQuery to a site collection via a feature. Time to get back to building the demo now the distraction has been dealt with…



Custom ASPX forms for SharePoint Workflows Part 1
June 27, 2009, 12:34 pm
Filed under: Cutomisation, Development, SharePoint, Workflow

Recently I needed to build a relatively simple notification workflow that included a custom form when the workflow was initially added to a list. In SharePoint workflow terminology, this is called an association form.

Super Quick Forms Overview

This is from the Workflow Forms Overview on MSDN. “[Forms] enable you to make your workflows more dynamic and flexible. Forms enable you to gather information from users at predefined times in the workflow’s life, as well as let users interact with the tasks for that workflow.” That all sounds great so what next?

If you are using MOSS then there are two options; InfoPath or ASP.NET (ASPX forms from now on). If you are using WSS then there is only one option; ASP.NET.

The difference between the two options is the amount of complexity involved to get them working and the level of flexibility each option provides. InfoPath forms are easier to implement but much less flexible. ASPX forms are much harder to implement but provide all the flexibility and robustness of the .NET framework.

Online Help for ASPX Forms Development

Perhaps it is just my search skills but I could find very little good information about how to implement the ASPX forms via the official channels. On MSDN there is a How to: Implement a SharePoint Workflow with ASP.NET Forms article which describes itself as a “high-level description” and also the Developer Introduction to Workflows for Windows SharePoint Services 3.0 and SharePoint Server 2007. A post on the SharePoint Team blog provides some other good overview material but it is still a little light on detail.

With a bit more searching I came across Serge Luca’s 15 part tutorials on workflow – these are not just on ASPX forms but provide examples about all sorts of workflow development tasks. Step 9, step 14 and step 15 are the posts specifically about ASPX forms. Serge’s examples are based on the Collect Feedback Workflow project which is part of the Office SDK (I came across a post by Andy Burns saying they had taken it out of the SDK so he has a link to a version in his post if you need it). Beware that the SDK project has a few bugs in it that need to be fixed.

Serge has also done a series of presentations on Microsoft Belux (a Belgium MSDN resource? I think the homepage is in Flemish but Serge’s presentations are all in English) that map closely to his series of posts.

In part 2 I will describe the notification workflow that I built and post some code examples including the bug fixes needed for the SDK workflow project.



Customise Breadcrumbs with jQuery the SharePoint Swiss-Army Knife
May 23, 2009, 2:22 pm
Filed under: Development, jQuery, SharePoint, WCM

Breadcrumbs in SharePoint seem to be a pet hate for many people, but they are a necessary evil as they provide a fundamental part of the SharePoint navigation. The stock standard SiteMapProvider SPContentMapProvider is good from within libraries and lists but is lousy for pages as described by Heather Solomon:

The main issue with the WSS site map provider is it will show directories you don’t want it to (mainly the Pages library) in the breadcrumb, and on some pages it will show ".aspx" on the end of the page name. The MOSS site map provider is more graceful, it just doesn’t show the list or library name in the breadcrumb.

So using the WSS breadcrumb we would get the following breadcrumb from within a library or list:

Site Name > Library or List Name > Folder Name

That is pretty useful for users, especially if they have a habit (I’m tempted to say bad habit!) of using folders to manage their content. The problem is what you see when viewing a page:

Site Name > Pages > PageName.aspx

What we really want to see is a very stripped down breadcrumb more like what the CurrentNavSiteMapProviderNoEncode provides:

Site Name

The best approach is to modify the relevant page layouts so we are using the CurrentNavSiteMapProviderNoEncode for our page level breadcrumbs. Then we have the SPContentMapProvider in the master page as the default breadcrumb provider and the nicer page level breadcrumb coming from CurrentNavSiteMapProviderNoEncode. The problem is what if we have lots of page layouts or even worse we don’t have any page layouts at our disposal – WSS or non publishing MOSS sites? Using a bit of jQuery we can mimic what the we could get with the CurrentNavSiteMapProviderNoEncode by using only the SPContentMapProvider breadcrumbs:

That might not be optimal jQuery (in fact I could almost guarantee its not so if anybody can suggest optimisations please let me know!) and this solution is not going to be very useful unless you can deploy it into your entire site via a web or site scoped feature. Jan Tielens provides a really good example on how to integrate jQuery into SharePoint using the AdditionalPageHead delegate control.

$(document).ready(function() {
	var pageIndex = -1;
	var offset = 2;
	var $spans = $("#ctl00_PlaceHolderTitleBreadcrumb_ContentMap > span");

	if($spans.eq($spans.length - 1).text().search(/\.aspx$/) > -1) {
		$spans.each(function(i) {
			if( $(this).text() == "Pages" ) {
				pageIndex = i;	
			}
		});	

		$spans.each(function(i) {
			if(i == (pageIndex - offset)) {
				$(this).addClass("ms-sitemapdirectional");
				var innerText = $(this).text();		
				$(this).empty();	
				$(this).text(innerText);
			} else if((pageIndex != -1) && (i > (pageIndex - offset))) {
				$(this).empty();
			}
		});
	}
});

Want to know more about jQuery? A simple google search on jQuery+SharePoint is a good start or take a look at what Jan Tielens or the guys and gals at End User SharePoint have got to say.



SharePoint Saturday Mornings

Perhaps this is a bit unhealthy but Saturday morning seems to the time when I am catching up with the aggregated feeds and generally perusing the web. A few recent posts stood out as pretty useful so this is my online reminder to have a look in some further detail again next week. Emailing the links won’t have the same effect as a quick post.

1.) Ivan Wilson was talking about the Storage Space Allocation Reports that can be viewed by Site Collection administrators. Generally SharePoint has some pretty basic reporting out-of-the-box, and these set of stats on the physical storage being used by lists, libraries and documents in your site collection definitely help in getting some better information about your SharePoint environment from SharePoint itself. I didn’t see anything about the sub-sites though? I am hoping there is some site usage reporting too as this is a fairly fundamental statistic. Largest sites in the site collection would definitely be one of the things I would want to view from a storage allocation report. Ivan mentions these reports are only available if the site collection has been allocated a storage quota, which is generally good practice to keep the site collection storage within some defined limits, and apart from getting managable site collection databases by using storage quotas there is the added bonus of these reports.

2.) Adding some structure to Wikis via templates by Michael Hofer was mentioned by the the folks at Get the Point. They said this approach was recently used by Microsoft for a critical project. That’s a pretty good endorsement so I think I am going to look at this one a bit more closely as it will fit some upcoming requirements on a project.

3.) Gary Lapointe picked up on something posted by Stefan Goßner that moving site collections between farms is now a supported operation via Backup/Restore. Previously the only “supported” method was an Import/Export, which I have always found pretty slow and it can sometimes have its quirks, not to mention you can’t retain any of the object ID’s (GUID’s) of the sites, lists and libraries which is a real pain when webparts in your site stop working. A custom import method like one of Garys commands or the very useful Content Migration Wizard by Chis O’Brien is generally needed and almost a necessity for many content deployment scenarios.  Even though moving site collections using the command line hasn’t been problematic for me so far, its good to know it’s now a supported method to move content between farms.




Follow

Get every new post delivered to your Inbox.

%d bloggers like this: