Blog Post

Porting a SharePoint 2007 WSPBuilder Solution to SharePoint 2010 — Part 3

Clavin Fernandes
Illustration: Porting a SharePoint 2007 WSPBuilder Solution to SharePoint 2010 — Part 3

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:

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.

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

  <!-- Settings screen in SP2007 Central Administration Application Management -->

  <CustomAction

    Id="Muhimbi.SharePoint.Administration.....ExternalService.DocumentConverterSettings"

    Title="Muhimbi Document Converter Settings"

    Location="Microsoft.SharePoint.Administration.ApplicationManagement"

    GroupId="ExternalService"

    Sequence="51"

  >

    <UrlAction Url="~site/_admin/Muhimbi.PDFConverter/WebAppDocumentConverterSettings.aspx"/>

  </CustomAction>

  <!-- Settings screen in SP2010 Central Administration Application Management -->

  <CustomAction

    Id="Muhimbi.....GeneralApplicationSettings.ExternalServiceConnections.DocumentConverterSettings"

    Title="Muhimbi Document Converter Settings"

    Description="Configure the Muhimbi Document Converter settings."

    Location="Microsoft.SharePoint.Administration.GeneralApplicationSettings"

    GroupId="ExternalServiceConnections"

    Sequence="51"

  >

    <UrlAction

        Url="/_admin/Muhimbi.PDFConverter/WebAppDocumentConverterSettings.aspx" />

  </CustomAction>

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:

  1. Open Central Administration and navigate to the section you want to place your link in.

  2. Write down the name of an ASPX file that is already in that section.

  3. Search in C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\FEATURES for all files containing that file name.

  4. Open the file and copy the GroupID and Location.

Central-Admin-PDF-Settings

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.

<CustomAction

Id="Muhimbi.SharePoint.DocumentConverter.PDF.Ribbon.Documents.Copies.Controls.PDFConversion.Action"

Location="CommandUI.Ribbon"

RegistrationType="ContentType"

RegistrationId="0x0101"

>

  <CommandUIExtension>

    <CommandUIDefinitions>

      <CommandUIDefinition

        Location="Ribbon.Documents.Copies.Controls._children">

        <Button Id="Muhimbi.SharePoint.DocumentConverter.PDF.Ribbon.Documents.Copies.Controls.

                    PDFConversion.Button"

                Command="Muhimbi.SharePoint.DocumentConverter.PDF.Ribbon.Documents.Copies.Controls.

                         PDFConversion.Button.Command"

                Image16by16="/_layouts/images/Muhimbi.PDFConverter/pdf16.gif"

                Image32by32="/_layouts/images/Muhimbi.PDFConverter/pdf32.gif"

                LabelText="$Resources:ecb_title;"

                Sequence="11"

                TemplateAlias="o1" />

      </CommandUIDefinition>

    </CommandUIDefinitions>

    <CommandUIHandlers>

      <CommandUIHandler

        Command="Muhimbi.SharePoint.DocumentConverter.PDF.Ribbon.Documents.Copies.Controls.

                 PDFConversion.Button.Command"

        CommandAction="javascript:window.location='{SiteUrl}/_layouts/Muhimbi.PDFConverter/

                       Convert.aspx?ListId={ListId}&amp;ItemId={ItemId}&amp;Source=' +

                       window.location"

        EnabledScript="javascript:function singleEnable()

        {

          var items = SP.ListOperation.Selection.getSelectedItems();

          var ci = CountDictionary(items);

          return (ci == 1);

        }

        singleEnable();" />

    </CommandUIHandlers>

  </CommandUIExtension>

</CustomAction>

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.

PDF-Converter-Doclib

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.

<!-- Additional SP2010 Styles. Disabled by default -->

<style id="sp2010AdditionalStyles" runat="server" Disabled="true">

.FixSP2010CheckBox {position:relative; top:2px}

#ctl00_PlaceHolderMain_convertersSection .ms-authoringcontrols IMG { display:none}

.FixSP2010Button {position:relative; top:-2px}

</style>

... Irrelevant code removed

<asp:Button id="btnTestServer" Text="Test" OnClick="btnTestServer_OnClick"

class="ms-ButtonHeightWidth FixSP2010Button" style="width:80px" runat="server"/>

... Irrelevant code removed

<wssawc:InputFormCheckBox ID="chkAllowWordProcessing" CssClass="FixSP2010CheckBox"

               LabelText="Word Processing (e.g. MS-Word, RTF, TXT)" runat="server"/>

<wssawc:InputFormCheckBox ID="chkAllowSpreadsheets" runat="server" CssClass="FixSP2010CheckBox"

               LabelText="Spreadsheets (e.g. Excel, CSV)"/>

... etc


_Changes to the ASPX Application page (Relevant fragments only)_


/// <summary>

/// Resolve the differences between SharePoint 2007 and 2010

/// </summary>

private void FixSharePointDifferences()

{

    int spVersion = SPFarm.Local.BuildVersion.Major;

    if (spVersion == 12)

    {

        // ** SharePoint 2007

        sp2010AdditionalStyles.Disabled = true;

    }

    else

    {

        // ** SharePoint 2010

        sp2010AdditionalStyles.Disabled = false;

    }

}

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.

SP2010-After-Fixing

SharePoint 2010 look and feel before and after fixing visual problems

Miscellaneous changes

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.

<%@ Page Language="C#" DynamicMasterPageFile="~masterurl/default.master"
Inherits="Muhimbi.SharePoint.DocumentConverter.PDF.Convert" %>

Continue to Part 4 – Updating deployment scripts.

Author
Clavin Fernandes Developer Relations and Support Services

Clavin is a Microsoft Business Applications MVP who supports 1,000+ high-level enterprise customers with challenges related to PDF conversion in combination with SharePoint on-premises Office 365, Azure, Nintex, K2, and Power Platform mostly no-code solutions.

Explore related topics

Share post
Free trial Ready to get started?
Free trial