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


Making Features that Deploy Content Types Compatible with the Content Type Hub
January 8, 2011, 10:55 am
Filed under: 2010, Content Types, Development, Tips & Tricks

* Update 15 May 2010 – this isn’t a problem! After some feedback from Chak’s and some retesting I’m happy to say that CAML features and the content type publishing hub work together fine. I can’t reproduce the problem and neither can Paul so I’m going to park this as a SharePoint X-File. I’d recommend you don’t use the method below unless you have a good reason to mix OM/CAML features in your deployment.

Paul Grimley wrote a post a while ago which highlighted a problem * with the content type publishing capability of SharePoint 2010. The particular problem highlighted by Paul’s post is the inability for content types to be published by the content type hub if they have been deployed by declarative CAML in a feature…seriously!

So we have two components of SharePoint 2010 – feature based content types and the content type hub – which are incompatible with each other. In my opinion there are lots of reasons you may want to deploy content types via features including:

  • Portability – deploying artefacts such as content types between environments such as DEVELOPMENT, UAT and PRODUCTION is much easier when they are wrapped up in a feature
  • Visual Studio 2010 support – you can leverage the content type SPI’s (SharePoint Project Item) for creating content types in your solution which provides a nice interface for selecting its parent etc etc
  • Readability – CAML based features are (sort of) human readable which sometimes makes it a lot easier to determine what is happening within the feature by reading the XML than the source code
  • Best Practice – haven’t we been told time and time again that it’s a best practice to deploy customisations to SharePoint via features and solutions?

So there are lots of reasons why we want to use features but we also want to use the content type hub, what are our options? After a bit of trial and error I came up with the following pattern that seems to work well albeit with a few limitations.

The Workaround

The API for 2010 provides a new constructor for the SPContentType class that lets us create a content type via the object model with a specified ID. This is a important change from the 2007 API which will be the basis of the workaround:

  • Create a base content type using the Object Model:
 string baseContentTypeId = "0x010100ee23a9df11631348b5a5ac7fdfd66b49";
SPContentTypeId contentTypeId = new SPContentTypeId(baseContentTypeId); SPContentType baseContentType = null;
baseContentType = contentTypes[contentTypeId];

if (baseContentType == null) {
	baseContentType = new SPContentType(contentTypeId, contentTypes, "Base Content Type Publishing");
	contentTypes.Add(baseContentType);
}
  • Any content types that should be publishable via the content type hub must be a descendant of this base content type (either a child, grand child etc)
<!-- Parent ContentType: Base Content Type Publishing (0x010100EE23A9DF11631348B5A5AC7FDFD66B49) -->
<contenttype id="0x010100EE23A9DF11631348B5A5AC7FDFD66B4900e54d81511bac4ad0837dd2ca3fb228e7" version="0" inherits="TRUE" description="A feature based Content Type that is publishable via the Content Type Hub" group="Custom Content Types" name="Base Document Content Type" />

My preference is to create the base content type via a ‘pre-requisite’ feature and then create a separate feature with the CAML based content types which will be dependent on this base content type feature. So far I’ve tested this ‘pattern’ with the following results:

  • These CAML based content types are disconnected from the features XML upon creation. This means any updates to the feature will not affect the content types. Updates to the published content types can be made by forcefully deactivating/reactivating the features but this is a risky operation as you might not know what has happened to the content types once they have been published.
  • If the attribute Overwrite=”TRUE” is included in either the content type or a field used by the content type the content type it won’t be published. It doesnt matter if the content type is a descendant of your base (publishable) content type or not it will never be published if you use the overwrite attribute.
  • These content types can be updated via the feature upgrade framework.

Unfortunately there are more than just a few things in SharePoint that you expect to work a certain way, or just work, that don’t. I love the platform but occasionally these “it almost works” moments can be pretty frustrating! If you have any feedback on this workaround I’d be keen to hear from you.

Advertisements


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


Christchurch SharePoint User Group Session 26/10/10: SharePoint Development With Visual Studio
October 27, 2010, 10:08 pm
Filed under: 2010, Development, SharePoint, SPUG, Tips & Tricks

I did a joint presentation with Alex Dean at the Christchurch SharePoint User Group which was a brief overview of SharePoint Development 2010 with Visual Studio 2010 and a discussion of some (not all) of the challenges. Alex kicked it off and did a great introduction and then I talked about a few of the problems I have experienced and how they can be worked around.

A big thanks to Alex for coming down from Wellington and doing two presentations. Great effort!

The slides (and of more use the links inside them) are on SlideShare and embedded below:



Code Camp Session: SharePoint 2010 Developer 101
September 7, 2010, 9:31 pm
Filed under: 2010, Development, Presentations, SharePoint

During the recent (August 29, 2010) Auckland Code Camp a buddy of mine Chaks had to pull out of a planned SharePoint 2010 developer session. Luckily Chan and myself were on hand to put together the following session which is a high level overview of SharePoint 2010 Development.

Feedback is always welcome on these sorts of things…but be kind we only had a couple of hours to prepare 🙂



What’s in Your SharePoint Toolbox?
September 19, 2009, 8:50 pm
Filed under: Administration, Development, SharePoint, Tools

This is both a thank you SharePoint community post and also another one of those resource listing posts. I think it is pretty fair to say the Community has provided many people with many of the tools and information that make our jobs easier. Acknowledging what has been helpful both recognises the Community and might direct people to something that they are looking for.

The massive end-user, IT pro, and developer community that has evolved around SharePoint has shared a rich set of tools, best practices, and guidance for the wider benefit of the SharePoint community. It should be mentioned there is also a lot of stuff out there in the wild that shouldn’t be adopted but I think that is the nature of all information on the internet.

Although we are drawing much closer to the public unveiling of SharePoint 2010, it is unlikely it will be available to the large majority of users until some time mid-next year (2010). In between then and now guidance around best practice will emerge and a whole new set of tools will be created and shared. The success of the current version of SharePoint (the huge number of WSS 3.0 and MOSS 2007 deployments) means the current set of tools will continue to be useful and necessary for some time yet.

So in no particular order…

SharePoint Administration / Deployment

  • SharePoint Manager 2007 – one of the most useful tools for SharePoint administrators and developers. It combines many of the features of the central administration, site settings menu and the SharePoint object model into a well-structured and easy-to-use GUI. The ability to inspect and possibly change almost any object/property in the SharePoint Farm makes it a really useful…SharePoint Manager.
  • SharePoint Content Deployment Wizard – this pretty much does what it says – it’s a content deployment tool with a friendly wizard driven interface. Chris O’Brien has developed an GUI for SharePoint’s native deployment API. Therefore, Content Deployment Wizard is a fully supported method of moving content between environments – it’s essentially the same process as used by STSADM’s export/import commands but it has more granular options. Among other things the Content Deployment Wizard lets you perform selective migrations using a nice GUI – really helpful when you only want to migrate a specific list or web instead of the entire site.
  • SharePoint Automation – these custom STSADM extensions by Gary LaPointe provide administrators with a huge number of additional operations that cannot be performed with the out-of-the-box STSAM commands. Often these would be things you would need to develop a custom (even throwaway) script for. At last count there were 143 commands and a growing set of PowerShell cmdlets.
  • Microsoft SharePoint Administration Toolkit – although not a community tool, this is a set of additional administration tools for both WSS and MOSS produced by Microsoft. There is a full overview on the SharePoint Team blog that explains in detail how the “[toolkit provides] functionality to address various difficult administrative tasks…[including] SharePoint Diagnostics Tool improvements, the Permissions Reporting Tool, the Quota Management command, and Security Configuration Wizard Manifests”. See the SharePoint Team blog for the download links, installation instructions and other useful documentation.

SharePoint Development

  • SharePoint Search Service Tool – allows you to connect to the search service of either MOSS or WSS via their web services. This is particularly helpful in inspecting the available scopes, managed properties, output of the search index and actually building the search queries. Using the SharePoint Search Service Tool’s GUI you can “build queries in either Keyword or SQL Syntax, submit those queries and examine the raw web service results”. The SharePoint Search Service Tool is useful not only in building up the search query syntax for reuse in web parts but as mentioned on the tools Codeplex homepage, it is very useful for “troubleshooting and verifying the behavior and configuration of a SharePoint environment”.
  • U2U CAML Query Builder – CAML queries are pretty difficult to write unless they are really trivial, and even the the syntax is easy to get wrong if you are doing it by hand. Luckily the good people from U2U have provided an interactive GUI that can connect to SharePoint and help you build the query and interactively inspect the results. Given the pervasiveness of CAML queries throughout SharePoint, this is one tool that is very useful for any SharePoint development.
  • STSDEV – a great alternative to the Visual Studio extensions for SharePoint Services (VSeWSS). It is, or should be, a well-known best practice that features, files and other customisations should be deployed to SharePoint using solution packages (WSP’s). STSDEV, VSeWSS and other Visual Studio add-ins, such as WSP Builder, provide an integrated method to package up the artefacts either created from, or included with a Visual Studio project into a deployable SharePoint solution file.
  • Warmup Scripts – SharePoint, like any ASP.NET application, is really slow for the first request to a page in the web application. This is because IIS and ASP.NET have to do an initial just-in-time (JIT) compile for that first request, which happens after an IISReset or application pool recycle has occurred. Most SharePoint application pools are set to recycle every night so this is always going to affect at least one user in the morning. Warmup scripts address this issue by making that first request to ensure the pages are compiled and ready to be served. There are many different flavours of warmup scripts including the SharePoint Warmup Job by Andrew Connell that manages the warmup requests from central admin and the Application Pool Manager by Spencer Harbar that allows both the recycling and warming up of application pools.
  • SharePoint Designer – everyone (should) know about SharePoint Designer by now, especially since it was made free by Microsoft. This powerful editor for SharePoint sites shouldn’t be dismissed by developers; the powerful dataview/dataform web part is an example of something that can be “developed” using SharePoint Designer.
  • CodePlex – this is where a large amount of the useful community tools and projects can be found. The MOSS Faceted Search, Community Kit for SharePoint and SmartTools for SharePoint are just a few examples and the list goes on.

Web Development

  • Firebug (for Firefox) – possibly the most useful web development tool ever – that’s a pretty big statement but I firmly believe it! Firebug is a Firefox plug-in (it has a sort-of-IE-version) that allows for the live inspection, editing and debugging of the HTML, CSS and JavaScript of a page. The CSS inspector is extremely useful when trying to track down what style rules are being applied to a specific element (and how they can be overridden in the case of Core.css).
  • YSlow (for Firefox) – “analyzes web pages and suggests ways to improve their performance based on a set of rules for high performance web pages” and is a must for anyone who is trying to improve the performance of a page. The rules that YSlow uses to determine the performance of the page all have recommendations on how they can be implemented. This is an excellent tool for improving page/site performance.
  • Fiddler – allows for the inspection of the HTTP traffic between your browser and the server. This includes all of the images, CSS and JavaScript that makes up the page and shows the HTTP codes, load times, compression settings and a myriad of other information for really inspecting what is happening during those requests. Firebug, YSlow and Fiddler all complement each other well and are an absolute must for any performance tuning of SharePoint pages and sites.
  • jQuery – the jQuery JavaScript library deals with many of the issues of cross-browser support then adds a huge set of methods “…that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development”. It’s a Swiss-army-knife for web development and one method of customising SharePoint to enhance the users experience.

General Development

  • RedGate .Net Reflector – is a free .NET assembly explorer. This tool is especially useful to check what version of the dll’s are being deployed with your SharePoint solutions – i.e. did I set the build to debug or release mode?
  • WinMerge – sometimes you just need to compare the difference between two files and WinMerge is great for quickly comparing and finding those differences.
  • EditPad Pro – this is notepad “on steroids”. There are a lot of alternative text editors available but EditPad’s built-in regular expression engine which then provides support for regular expressions during find and replace is invaluable.
  • Log Parser Lizard – I have only used this tool a few times but it was so helpful that I thought it was worth mentioning. Also the credit goes to Todd Klindt as I came across it on a blog post of his. In a nutshell, Log Parser Lizard is a GUI for Microsoft’s Log Parser. Log Parser allows for SQL-like syntax to be used to query text-based data such as log files, XML and CSV files. Log Parser Lizard wraps the complexity of the command-line operations of Log Parser into a nice GUI and includes lots of pre-canned queries out-of-the-box.

SharePoint seems to be the type of product where there is more than one tool to achieve a task and often there is the need for more than one tool to complete that task. These are the tools that I have used consistently and found really helpful and I know there are a lot more out there than this less-than-exhaustive list. If you have any really good tools that you would like to share then please leave a comment.



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.




%d bloggers like this: