Customizing the suite bar branding with a SuiteBarBrandingDelegate delegate control

The out-of-the-box master pages included with SharePoint 2013 provide a delegate control to place branding text in the top-left corner of the page. For standard SharePoint instances, the text SharePoint is displayed. For SharePoint on Office 365, Office 365 is displayed instead.

Customizing the suite bar branding with a SuiteBarBrandingDelegate delegate control

In this recipe, we will simply replace the control with a custom control that displays our own text. The text could also be replaced by editing the master page or by modifying the SuiteBarBrandingElementHtml property on the SharePoint web application. Using the custom control provides us the ability to add additional functionality if desired. For instance, the control could be used to add additional links, a menu, or other interactive content.

Getting ready

We should have already created our Visual Studio project in the Creating a Visual Studio solution for custom delegate controls recipe of this chapter before starting this recipe.

How to do it...

Follow these steps to replace the suite bar branding text using a delegate control:

  1. Open the project created in the Creating a Visual Studio solution for custom delegate controls recipe of this chapter in Visual Studio.
  2. Right-click on the subfolder we previously created in the CONTROLTEMPLATES mapped folder.
  3. Navigate to Add | New Item.
  4. Select User Control by navigating to Visual C# Items | Office/SharePoint.
  5. Provide the item a name, CustomSuiteBarBranding.ascx for example and then click on Add.
  6. Open the newly created ASCX file if it is not already open.
  7. In the body of the user control, add our custom branding text as follows:
    <div class="ms-core-brandingText">Custom SharePoint Branding Text</div>
  8. Right-click on the project name in the Solution Explorer pane.
  9. Navigate to Add | New Item.
  10. Select Empty Element by navigating to Visual C# Items | Office/SharePoint.
  11. Provide the new item a name, CustomSuiteBarBranding for example.
  12. Click on Add.
  13. In the newly created Elements.xml file from the new element, register our custom control with the SuiteBarBrandingDelegate control as follows:
    <?xml version="1.0" encoding="utf-8"?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
      <Control Id="SuiteBarBrandingDelegate"
      Sequence="10"
      ControlSrc="~/_controltemplates/15/Code6587EN.Ch07/CustomSuiteBarBranding.ascx">
      </Control>
    </Elements>
  14. Add a new safe control entry to the new element with the following details:
    • (Name): CustomSuiteBarBranding (the name of the user control we created without the .ascx extension)
    • Assembly: $SharePoint.Project.AssemblyFullName$
    • Namespace: Code6587EN.Ch07.CONTROLTEMPLATES.Code6587EN.Ch07 (the full namespace for the user control, without the name of the class itself)
    • Safe: True
    • Safe Against Script: True
    • Type Name: CustomSuiteBarBranding (the name of the class for the user control)
  15. Open the feature created previously. Ensure that the new element is included in the feature:
    How to do it...
  16. Click on Start from the toolbar to deploy the solution and attach the debugger.
  17. Once the SharePoint site is loaded in the web browser (after clicking on Start), observe the new branding text as shown in the following screenshot:
    How to do it...

How it works...

The out-of-the-box control used by the SuiteBarBrandingDelegate delegate control displays the HTML snippet stored in the SuiteBarBrandingElementHtml property of the current SharePoint web application. In this recipe, we replaced the default control with our own delegate control that adds our text to the page.

We are using the same CSS class that the out-of-the-box text uses to allow the content to display with the standard style. Relying on the SharePoint classes allows the content to inherit the styles provided by the current SharePoint theme.

See also

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.137.7