In part of 3 of our series about porting a SharePoint 2007 based WSPBuilder project to SharePoint 2010 we discuss the changes made to our code in order to make everything work, and look good, in both versions of SharePoint
Please note that this article is based on our experiences with the beta version of SharePoint 2010. Some of the issues we have identified may have been resolved in the final release.
The following posts are part of this series:
- Part 1 – Introduction / Problems installing the existing 2007 version on SP2010
- Part 2 – Reconfiguring the Visual Studio Solution
- Part 3 – Programmatic / visual changes (This post)
- Part 4 – Updating deployment scripts
Fixing Central Administration links
We started of with the easy bit that required no coding, unless you consider writing XML files coding. As the configuration screen for our PDF Converter is located under External Service Connections in SharePoint 2007, we decided to add it to the same location in SharePoint 2010.
We added the Custom Action for SharePoint 2010 to the same elements file that holds the SharePoint 2007 definition. SharePoint will simply ignore locations it has no knowledge about, which is very convenient in this case.
Updated elements.xml file. Note that some IDs have been truncated for readability
Note that we had to change both the GroupID and Location for SharePoint 2010. At the time of writing a full list of Groups and Locations has not yet been published by Microsoft, but Arjen Bloemsma has created his own preliminary list. If the location you want to target is not found in Arjen’s list then you can follow the procedure set out below:
- Open Central Administration and navigate to the section you want to place your link in.
- Write down the name of an ASPX file that is already in that section.
- Search in C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\FEATURES for all files containing that file name.
- Open the file and copy the GroupID and Location.
Muhimbi Document Converter Settings in External Service Connections
Adding support for the Ribbon
With the links in Central Administration fixed we moved on to the SharePoint 2010 Ribbon. As we didn’t want to introduce too much change to our back end, we decided to only allow a single document to be selected for conversion at a time. Fortunately the SharePoint team had just provided an example on their blog about disabling a Ribbon button when more than 1 item is selected. Unfortunately their code didn’t work, but it gave us a good starting point.
The Ribbon is quite well documented. For details see:
Once we had the Ribbon changes up and running on SharePoint 2010 we noticed that SharePoint 2007 was no longer able to accept the WSP file. As a result we decided to create a shadow SPHive_2010 folder and modify our build scripts to create two separate WSP Files. For more details see Part 2 – Reconfiguring the Visual Studio Solution.
Custom Action for the PDF Conversion button and script to only allow a single selection
Note that we have wrapped some lines in the code listed above to make things more readable. When copying this code, please make sure everything between double quotes, with the exception of the EnabledScript attribute, is placed on a single line.
Look at our new button in the Ribbon, isn’t it shiny?
Fixing visual problems
As you may remember from Part 1 – Introduction / Problems installing the existing 2007 version on SP2010, the formatting of certain page elements don’t look quite right in SharePoint 2010. The main problems were related to the vertical spacing of check boxes and additional vertical space being added between elements.
After some investigation we decided that the easiest way to solve these rending problems was to add a little bit of conditional code that checks the version number of SharePoint and depending on the version output some additional CSS styles.
Changes to the Code Behind file. Invoke this method from the page’s OnLoad
With these changes in place the screens suddenly look a lot better in SharePoint 2010. As the style changes are not active in SharePoint 2007 everything continues to work fine in that environment as well.
SharePoint 2010 look and feel before and after fixing visual problems
In addition to some minor code changes, the addition of the DynamicMasterPageFile attribute is worth mentioning as well. By replacing the MasterPageFile attribute - in Application Pages hosted inside a site collection - with DynamicMasterPageFile, the Quick Access menu is magically added to the left of the page. The absence of this menu in previous SharePoint versions has always been a pet peeve to me.
Note that this new attribute is incompatible with SharePoint 2007. Therefore a copy of the ASPX file with the MasterPageFile attribute replaced with DynamicMasterPageFile will need to be placed in the shadow SPHive_2010 folder. We tried setting this value manually (via reflection) in the page’s PreInit event, but that resulted in the SharePoint 2010 page being rendered in the SharePoint 2007 look and feel.
Continue to Part 4 – Updating deployment scripts.