Wednesday, August 20, 2008

A compliant navigation control for SharePoint.

Following on from my post about creating a MOSS WCM website using a div based layout, I am going to describe a simple way to create a web standards compliant navigation control.

One of the short comings of the sharepoint:aspmenu or the asp:menu control is that they render horrible table tags. By using CSS adapters (Check out CSS Friendly) we can still take advantage of the built in controls but render the output in div and ul, li tags to create our site navigation. I use the MOSS PortalSiteMapProvider as my site map provider.

1) Firstly I created an empty class definition (MyMenu) that inherits from System.Web.WebControls.Menu.

 
public class MyMenu : System.Web.WebControls.Menu
{
}


This is done so that we have explicit control over which controls are adapted. If we decided to adapt the System.Web.WebControls.Menu directly all controls of this type would get rewritten even if we didn't want them to. This happened to me the first time I tried it in SharePoint, I ended up modifying every menu in the site including the Site settings and Application pages, obviously these are will not be seen by the anonymous user, hence I am not concerned by the fact they render in table tags.

2) Download the CSS Friendly Adapters either download the source code and sign the assembly (we can now place the code in the GAC) or place the binary in the Web application /bin folder. You may have to raise the trust level in the Web.config also.

3) Create a .browser file that adapts our control in 1) using the adapter in 2) an example of this is shown in the CSS Friendly project.

4) finally I wrapped the MyMenu control and PortalSiteMapProvider into a SharePoint ControlTemplate ascx. This was done to a) to keep my master page clean and tidy, and b) to remove some of the complexity of configuring the site map provider for future reuse.

5) Add the control template to the masterpage.

6) We can now style the control as normal using our custom .css file.

For more information and a tidy implementation of adapting a "wizard" control check out Toke's blog post here.

Sorting Generic List<> using Lambda expressions.

I have been having a play with C#3.0, specifically around sorting collections using Lambda expressions. i.e. a collection of navigation items. Here is a great blog post that clearly explains the basics. Using lambda expressions and linq for manipulation of collections.

Saturday, August 16, 2008

A pattern for creating a MOSS WCM website

Recently I have been working on MOSS WCM websites. I have developed a successful pattern to create branded websites where the design team doesn't need any specific SharePoint knowledge or experience to create great looking layer(<'div'>) based sites.

1) Created a Site Defintion based on either the STS Blank Site Definition or the base Publishing Site Definition.

2) Create a feature stapler to staple new fuctionality to the new Site Definition. By using a feature staple we can remove the complexity associated with creating Custom Site definitions.

3) Create a "Masterpage Feature"; this feature adds a new (<'div'>) based masterpage extending minimal.master, and a alternate .CSS file to the _catalogs/masterpage library as "ghostable" files.
The feature assigns the .master and .css to the site.
Because the files are set as ghostable all changes affecting sites using this def can be made to a single instance of the .master and .css file in the Feature folder. (This alternate .css file is the last .css rendered in the CSS hierarchy; this means the creative designer can create all their own classes that relate to the .master and effectively ignore all of the OOB SharePoint styling)
This feature also removes the default Page Layouts and stylesheets that get put in the "Style Library" library by default.

4) All creative resources can now be deployed using a Solution to the 12/TEMPLATE/IMAGES/ folder and referenced in the .CSS file


Result; we now a have beautiful a div based site, and the creative designer doesn't need any SharePoint specific knowledge.