Aidan Garnish

Collaboration Not Competition

JQuery Library for SharePoint

Up until now I have tended to agree with people like Jeremy Thake who warn against the use of jQuery in your SharePoint deployment. **UPDATE** - see comments from Jeremy below clarifying his position on who should be using jQuery.

However, a common requirement from users is to provide cascading drop down boxes in the new and edit item forms which SharePoint just doesn't provide out of the box.

I then came across Marc Anderson's excellent jQuery library for SharePoint which provides a solution for creating cascading drop downs as well as several other very useful functions.

Although this does not address all the issues of using jQuery I think that it helps to overcome some of them.

  1. The cascade function has already been tested for SharePoint 2010 so I know it won't break when we upgrade.
  2. It is a library which can be reused across SharePoint with minimal additional script needing to be added to individual pages so it can be maintained and updated centrally.
  3. It is a Codeplex project that is relatively popular so I can have some confidence that it will continue to be updated and even if it isn't I have a copy of the library that I can update myself if anything ever became broken in future versions of SharePoint.


For more information on the library and the SPCascadeDropdowns functionality take a look here.

SharePoint Custom Workflow Visual Studio Solution

There are loads of articles and blog posts about creating SharePoint 2007 custom workflows using Visual Studio but most of them only tell part of the story or have certain steps missing. Nick Swan has probably come closest with his post for Visual Studio 2005 but even with a post as comprehensive as this it is clear from the comments that it is something people still struggle with. Rather than rehash all of those posts I thought it would be more useful to provide an example Visual Studio 2008 solution that is already set up and ready to go.

This article does not aim to be a comprehensive guide to setting up a custom workflow. It is aimed at a .net developer audience who are already familiar with SharePoint and InfoPath development but who just need a bit of help bring all the bits of SharePoint custom workflow development together into a working solution.

This solution was created using STSDev v1.4 which gives a good starting point for a sequential workflow solution and automatically creates a .wsp file whenever the project is built. If you are not familiar with STSDev projects the .wsp can be found in the Deployment folder of the project.

In the project I have included the more common generic elements for a custom SharePoint workflow:

  • An InfoPath initiation form that allows the user to provide information to the workflow task. In this case the workflow task title is set and a property is stored to be displayed later on the task form.
  • An InfoPath task form that displays information from the initiation form and allows the user to approve or reject the the item.
  • The sequential workflow itself - wiring this up is often a place where people miss something or make mistakes.
  • A WorkflowTestInitForm.cs file that is used to make the information typed into the initialisaton form available in code. See comments in this file to generate your own.
  • An ItemMetaData.xml file that is used by the InfoPath task form as a secondary data source so that the information supplied by the initiation form can be displayed.

The code has been commented to provide additional information and guidance on how to set up your own workflows. For the solution to work the only thing you have to change before building and deploying the .wsp is line 62 in SequentialWorkflow01.cs - the task assigned to property must be set to a user that is valid for your environment.

To open the solution just save this zip and extract in your development environment - (91.97 kb)

SharePoint Customisation - OOTB vs SPD vs Custom Code

@joyknows has posed an interesting SharePoint question via Twitter -

What would you say are the primary strengths and weaknesses of OOTB customisation vs. SPD vs custom code?

This one is definitely going to take more than 140 characters so here goes...

Out of the box (OOTB) customisation allows any end user familiar with SharePoint to create sites, lists and web parts through the user interface to produce something that meets their specific requirements.

Strengths -

  • Very quick to create customisations
  • Anybody with basic SharePoint knowledge can do it
  • Forces users to create solutions in a "SharePoint way" which encourages consistency

Weaknesses -

  • Doesn't provide much flexibility - compromises have to be made with requirements
  • If you want to repeat the same customisations again then options for recreating the solution are limited - manual repetition of creation steps or templates

SharePoint Designer (SPD) customisation allows power users to get a bit more creative and make use of some of the more advanced options in SharePoint such as custom workflows and connecting to differnt data sources.

Strengths -

  • More options for customisation - will fulfill more of the original requirements
  • Make changes to master pages and page layouts - create a completely new look and feel

Weaknesses -

  • Difficult to deploy customisations made using SPD to other sites - eg. A custom workflow created in SPD is applied to a specific list and cannot be resused on another list. The only option is to manually recreate the workflow again for the next list.
  • It is possible to do a lot of damage very quickly if put into untrained hands
  • Once files are customised by SPD they cannot be changed by custom code

Custom code requires a SharePoint developer to write it but it is the most powerful option that opens up the full SharePoint API, web services and any other code you want to use to customise your solutions.

Strengths -

  • Provides the most options for customisation
  • Customisations can be packaged up as features that are easily deployed and reused in multiple solutions
  • Deployment can be controlled and governed more easily as customisations can only be deployed by people with SharePoint admin permissions

Weaknesses -

  • Requires a SharePoint developer
  • Takes longer to achieve the same results

The above lists are a very brief summary of the pros and cons for each option. In reality it would be possible to have lengthy discussions about each but I think these lists provide a fair summary that should help as a primer for the more important discussion - which option should I choose?

As with most decisions like this the short answer is - it depends. In this case it depends largely on the trade off that you are prepared to make between speed of solution develoment and flexibility/meeting the original requrements exactly.

If you need something fast and are prepared to compromise by not meeting the original requirements 100% perfectly then OOTB is the way to go.

If, on the other hand, you need to have a solution that ticks off every requirement perfectly, that can be easily reproduced across lots of sites and you are prepared to wait a bit longer for delivery then custom code is the answer.

SharePoint Designer is a middle ground that combines the best and worst of all the options. In my opinion it should only be used to quickly prototype something that you later turn into a well packaged custom code solution or where you have to customise to meet a requirement but do not have SharePoint development resources available.

In the interests of full disclosure I am from a SharePoint development background and have also spent a significant amount of time working with SharePoint whilst being constrained to only using OOTB customisations. As a result I am not what I would describe as a typical SharePoint dev - ie. Reach for Visual Studio first and ask questions later!

This may sound like a betrayal of my SharePoint developer brothers and sisters but I would argue that custom code should only be used once you are sure that what is being asked for cannot be achieved using OOTB customisation. That may sound obvious but it is easy to take requirements on face value and assume that what the end user is asking for cannot be compromised on which makes it look as though custom code is the only option. In reality if the end user understands that they can have a solution that meets 80% of the requirements delivered in 2 days using OOTB or a solution that meets 100% of the the requirements in 10 days using custom code those requirements that were previously set in stone suddenly become a bit more flexible.

So in summary, and just to be clear so I don't get flamed by all the SharePoint devs, custom code is great. It provides the most number of customisation options that can be deployed to your SharePoint farm in a repeatable and controlled way. However, I would choose OOTB wherever possible in the interests of speed of delivery and productivity even if that means using your powers of persuasion to talk the end user into settling for a solution that doesn't tick off 100% of the original requirements but does meet the core ones, they will thank you in the end!

SharePoint support turns from a trickle to a flood

When Microsoft Office SharePoint Server 2007 was in beta, and for some time after it was given a full release, the level of support and documentation available was, at best, pretty sketchy. Over time Microsoft have improved what is available on MSDN and Technet as well as publishing best practices but what really saved MOSS 2007 and the people who work with it was the SharePoint community who have done a great job in supporting each other with blog posts, forums, wikis, white papers and the like.

Given that history, it is fantastic to see the amount of information being made available before the public beta of SharePoint 2010 is even released. As the NDA on SharePoint 2010 was lifted at the SharePoint conference in Las Vegas there was a veritable blizzard of blog posts from various SharePoint insiders.

Other than watching the SharePoint conference key note one of the best summaries of top new features came from Joel Oleson and also includes further links to the MSDN and Technet documentation for SharePoint 2010 as well as what looks like quite a promising Developer Centre being created by Microsoft that is currently tagged as in beta. Joel has also started doing some presentations on the new admin features of SharePoint 2010 with further information on his blog.

Andrew Connell was quick off the mark with 3 blog posts on improvements to the Web Content Management aspects of SharePoint 2010 and a further post on the new service application architecture.

Bil Simser filled in some of the details around improvements to look up columns and the addition of ratings functionality.

Spencer Harbar has produced a great post on the improvements to the development tools available for SharePoint 2010 which will all be very welcome given the amount of criticism Microsoft got from the development community for not doing more in this area for the previous version.

Another brilliant developer post on the factors that could persuade developers to start using SharePoint comes from Jeremy Thake the man behind SharePoint Dev Wiki. This is a wiki that was started as a reaction to the lack of a definitive resource for SharePoint developers and has become the place to go for reference material and guidance on SharePoint development. The site has now been extended to include a SharePoint 2007 Administration wiki and a shiny new SharePoint 2010 Development wiki which is already starting to be filled with content.

A communication method that wasn't available when the 2007 version was released was Twitter. Not being able to go to the SharePoint conference was frustrating but Twitter came to the rescue and at times it was almost like being there. Well, ok, maybe not but it did provide a rich stream of information about new features directly from the people who were lucky enough to be there. This allowed the people who couldn't be there in person to get a glimpse of some of the detail being revealed during the sessions and to see beyond the headlines of the keynote.

Back in the beta days of SharePoint 2007 it was often a case of feeling your way and piecing together bits of information from lots of different sources to achieve the end result you were looking for. I think I can say with some confidence that those bad old days are in the past for SharePoint. It is now a huge success story for Microsoft and they are supporting it better than ever with documentation and tools. In addition the community of people working with and supporting SharePoint has grown massively over the last few years and this is where a lot of the best content is going to come from. This time round the problem won't be the lack of information the issue will be that now the trickle has turned to a flood can we keep up with all the content being produced? This is where inititiatives like Dev Wiki can really help to put some structure to that content and also allows us to give authority to the best bits.

Have you come across any other great SharePoint 2010 posts that are worth sharing? If so please add them in the comments.

Easily import data from CSV and SQL to a SharePoint list

CSV and SQL importer wsp file

This SharePoint feature allows you to quickly import data from a CSV file or a SQL stored procedure to any custom SharePoint list.

Once you have added the solution to your farm and activated it on your site collection an additional menu option will be available on the Action menu of each custom list that will take you to the import CSV or SQL page.

Simply select which option you want - either import from a CSV file or import from a SQL stored procedure. Next, browse to the CSV file or enter the SQL connection and name of the stored procedure and hit the Import button.

There is a check box option to delete all items from the list before doing the import which is not selected by default.

IMPORTANT - the first line of the CSV file must contain the names of the SharePoint list columns you want to import the data to. Eg. If you want to import data into a list that has two columns called Title and Description then the first row of the CSV file will be Title, Description.

If you are using SQL then the stored procedure for the example above would need to be something like: SELECT Title, Description from [TableName]

**UPDATE 16/12/2012 - I have now updated the CSV Upload portion of this feature to work as a SharePoint 2013 Hosted Solution.

Trouble shooting SPWeb object closed or disposed

I recently came across an issue on a WCM site where the following error was being shown whenever a dropdown selection was changed on a custom web part:
SPException: Trying to use an SPWeb object that has been closed or disposed and is no longer valid 

This looked like the SPWeb object was being incorrectly disposed of but careful inspection of the web part showed that best practices for disposal of SPObjects had been followed .
To try and track down the cause of the error and to really satisfy myself that it wasn't the web part causing the issue I removed all references to SPWeb from the custom web part. The error was still appearing so this ruled out bad coding practice in this control.
The next step was to take a look at the other controls on the page. As this was a WCM site there were a number of custom controls being used for navigation and other functionality.
It didn't take too long to track down the culprit in a control being used to set the site title in the browser title bar. This contained the following:
using(SPWeb web = SPContext.Current.Web)
   //some code
When the dropdown selection was changed a postback was fired and this piece of code brought the site crashing down.
This was because both the using statement and the use of SPContext handle garbage collection so the SPWeb object was being disposed of twice and as it didn't exist on the second dispose the error above was thrown.
Once corrected the code looked like this:
SPWeb web = SPContext.Current.Web;
//some code 

Most of the links about this error on the web will point you towards the issue being incorrect disposal of objects but what is learnt here is that it might not be a coding issue in the control that seems to be causing the problem. In this case it was the postback being fired by the control rather than the control itself that was triggering the error. The root cause was actually a completely different web part on the page.

SharePoint projects are like vegetables

SharePoint is often marketed as a way for businesses to deliver results quickly. The breadth of capabilities in SharePoint is impressive straight out of the box – collaboration, search, business intelligence, web content management and the rest. Because you get all of this without any custom development it is possible to deliver SharePoint solutions to the business very quickly without having to write a line of code.

At this point the title of my post may seem a little misleading. SharePoint and vegetable growing are definitely not similar in terms of speed of delivery or quick wins but bear with me.

I recently planted some vegetable seeds and I can now tell you from my limited gardening experience that it takes a while for lettuce, potatoes, chillies and tomatoes to make progress from being tiny seeds to being little shoots. Delivering results in the form of tasty things I can eat still seems a very long way off.

In a world where we are seemingly obsessed with instant gratification growing your own vegetables forces you to slow down and accept that whilst there are things you can do to encourage growth there is also a natural cycle that cannot be rushed.

Whilst sitting in the garden wondering how long it was going to take before I could make a meal from the things I was growing I started thinking about how different this was to how I spend my rather more fast paced working life delivering SharePoint solutions. However, the more I thought about it the more similarities I saw. A truly successful SharePoint implementation isn’t going to survive based on those initial quick wins it is going to be judged on the value that it provides to the business over time as it continues to grow and develop to maturity. I started thinking about the SharePoint projects I have been involved in and particularly those that involve intranets and lots of business users. Whilst SharePoint does provide a huge amount out of the box that can produce quick wins and deliver fast results there also seems to be a natural cycle to SharePoint success that cannot be rushed, although there are things you can do to speed it up.

Thanks for making it this far, I promise that this is where the similarities between vegetable growing and SharePoint start to become clearer, in my slightly warped mind anyway. In any SharePoint or gardening project there is initially a flurry of activity where the infrastructure or garden is prepared. Any existing content or compost is migrated from the current infrastructure or garden to provide a useful or fertile environment for users or seeds to become a part of.

The users or seeds are then given access to the content or compost and the first shoots of use or growth appear. At this point everything looks good and you could be fooled into thinking that your job as an IT professional/gardener is over, think again. Those users or seeds are going to need supporting or watering and some of them are simply going to lose faith with the project or wither and die unless you provide training or protection from the elements.

Over time the content or garden can become a bit of a mess and data cleansing or weeding is necessary otherwise your users or vegetables will not be able to get to the content or nutrients they need to prosper and meet their full potential. As with all SharePoint project or gardening tasks this is not something you can just do once and tick it off a list. It is a never ending process of supporting or watering, training or protecting, removing clutter or weeding.

Often a SharePoint project is seen like any other IT infrastructure project that has a start and an end date which will produce immediate results as soon as the magical project end date is reached. This is the gardening equivalent of digging over your vegetable patch, adding compost and nutrients to the soil and then going back indoors thinking your job was done. People are then surprised when nothing grows and the vegetable patch is still empty come the summer. When this happens in a SharePoint project it is usually the technology that gets the blame for underperformance rather than a lack of governance or assurance plan.

The concept of SharePoint as an ongoing process rather than a fixed term project is crucial to the success of SharePoint within an organisation. Although there are quick wins to be had when you first implement SharePoint depending on your circumstances the tastiest rewards will only come in time if you carefully tend to your installation and feed your users the right mix of training, knowledge and support.

WCM SharePoint utilities

I have created a number of small utility console applications and web parts that are useful for quickly completing a few fairly common tasks - well if you are a SharePoint dev anyway. They are all fairly rough and ready but the project code can be downloaded from the link below if you want to make your own additions/improvements.

These applicatons all have the power to make lots of changes to your site collection very quickly so use them at your own risk - backup your site and always test them in a non-production environment first, you have been warned!

Download projects here

Modify Workflows

Update the properties on approval workflows. This is particularly useful for WCM sites where each subsite has it's own Pages library and workflow by default. This means that once you have a decent sized site collection hierarchy it could take a very long time to go through every site and change the workflows. This app allows you to quickly update properties such as whether users can change who the approver is when submitting a page for approval and whether a single task is assigned to a group. This is a console application so settings are changed through the app.config.

Uncustomize Files

Customized files are the plague of any SharePoint developer who wants to be able to update page layouts, master pages or any other file that makes up a SharePoint site. A customized file is a file that has been modified in SharePoint Designer and is therefore different to the original site definition file that was used when the site was created. A customized file stores it's customizations in SQL so the file on disk is no longer used which means your update of the file on disk is ignored. If you are wondering why your updates are not overwriting the files on your site then it is worth checking to see if the file has been customized. If it has then you will probably want to find out why and what the customization is and then maybe revert it to it's uncustomized state. The UncustomizeFiles console application allows you to do just that.

WCM Control Panel

Quite a grand title for something that at the moment only does two things - if anyone has any ideas for what else they would like to see on a WCM control panel please leave a comment. This web part will tell you how many pages there are in a WCM site collection, something I had hoped CQWP would do but unfortunately not (if anyone knows of a better OOB way of getting this information please let me know in the comments). It will also list out the number of pages in each individual subsite if you modify the web part settings.

The second function this web part has is to Update All Pages which simply checks out every page and then checks it back in then publishes and approves the page. This is a bit of a cheat for people who want to make their content look more up to date than it is for Internet sites where a last updated date is displayed on each page. In reality this is actually quite useful for launch day to be able to create the right impression for users - especially if you have had a particularly long content creation cycle before going live.

These projects can be downloaded here

Twitter SharePoint web part - another update!

** Update June 2010 - new Twitter web part using OAuth rather than Basic Auth **

When I mentioned that I was developing a Twitter web part to Mirjam van Olst she asked if it would be possible to work on it with me. So thanks to Mirjam, in the true spirit of international collaboration, we are now able to bring you an updated version of the web part which is more secure and easier to deploy.

Improvements include -

  • The password input now uses a password textbox to protect the Twitter credentials
  • TwitterLib.dll has been added to the wsp for easier deployment

Download the new and improved Dutch/British/Euro version here: TwitterPublicTimeline.wsp (24.25 kb)