Share via


SharePoint 2013: Implement Custom SuiteLinks Delegate Control


SuiteLinksDelegate

It is a new delegate control introduced in SharePoint 2013. If you are looking to add a new link just next to “Sites, NewsFeed, SkyDrive” etc, on the top bar of your SharePoint site you can now do that with a new delegate control "SuiteLinksDelegate". The SuiteLinksDelegate control will allow us to modify the default links,

For Example: To add our own links, in the "suit links".

Header before

http://csharpcorner.mindcrackerinc.netdna-cdn.com/UploadFile/sagarp/implement-custom-suitelinks-delegate-control-in-sharepoint-2/Images/Header.jpg** **

Step 1: Create One Empty SharePoint Project and provide the Solution Name and choose the Solution Path and click OK.

Step 2: Deploy the Solution as Farm Solution. Provide the Url in next screen and validate the connection.

Step 3: Add New UserControl to the Project from the Templates and provide a Name to it, in our case it is “MyCustomSuiteLinksDelegate

http://csharpcorner.mindcrackerinc.netdna-cdn.com/UploadFile/sagarp/implement-custom-suitelinks-delegate-control-in-sharepoint-2/Images/UserControl.jpg 

Now our Solution Explorer looks as follows,

http://csharpcorner.mindcrackerinc.netdna-cdn.com/UploadFile/sagarp/implement-custom-suitelinks-delegate-control-in-sharepoint-2/Images/MyCustomSuiteLinksDelegate.jpg

Step 4: Add reference to Microsoft.SharePoint.Portal dll.

http://csharpcorner.mindcrackerinc.netdna-cdn.com/UploadFile/sagarp/implement-custom-suitelinks-delegate-control-in-sharepoint-2/Images/Solution%20Explorer.jpg

 

Ensure your control inherits from MySuiteLinksUserControl like this:

 

public partial class MyCustomSuiteLinksDelegate: MySuiteLinksUserControl

Step 5: Code snippet for the ascx.cs file.

  1. using System;  
  2. using System.Web.UI;  
  3. using System.Web.UI.WebControls;  
  4. using System.Web.UI.WebControls.WebParts;  
  5. using Microsoft.SharePoint;  
  6. using Microsoft.SharePoint.Utilities;  
  7. using Microsoft.SharePoint.WebControls;  
  8. using System.Globalization;  
  9. using System.IO;  
  10. using System.Collections;  
  11. using Microsoft.SharePoint.Portal;  
  12. using Microsoft.SharePoint.Portal.WebControls;  
  13. namespace SuiteBarBrandingDelegate_Example.ControlTemplates.SuiteLinksDelegate_Example  
  14. {  
  15.     public partial class MyCustomSuiteLinksDelegate: MySuiteLinksUserControl
  16.     {  
  17.         protected void Page_Load(object sender, EventArgs e)  
  18.         {}  
  19.         protected override void Render(HtmlTextWriter writer)  
  20.         {  
  21.             writer.RenderBeginTag(HtmlTextWriterTag.Style);  
  22.             writer.Write(".ms-core-suiteLinkList {display: inline-block;}");  
  23.             writer.RenderEndTag();  
  24.             writer.AddAttribute(HtmlTextWriterAttribute.Class, "ms-core-suiteLinkList");  
  25.             writer.RenderBeginTag(HtmlTextWriterTag.Ul);  
  26.             RenderSuiteLink(writer, "http://AboutUs/", "About Us", "lnkSearchLink", false);  
  27.             RenderSuiteLink(writer, "http://ContactUs/", "Contact Us", "lnkSearchLink", false);  
  28.             RenderSuiteLink(writer, "http://Feedback", "Requisition Manager", "lnkSearchLink", false);  
  29.             writer.RenderEndTag();  
  30.             base.Render(writer);  
  31.         }  
  32.     }  
  33. }  

Step 6: Add Elements.xml file to the Solution, provide the name and click Add.

http://csharpcorner.mindcrackerinc.netdna-cdn.com/UploadFile/sagarp/implement-custom-suitelinks-delegate-control-in-sharepoint-2/Images/Elements.jpg

Step 7: Click on elements.xml file and paste the following code snippet inside the elements tag.

  1. <?xml version="1.0" encoding="utf-8"?>  
  2.     <Elements xmlns="http://schemas.microsoft.com/sharepoint/">  
  3.         <!-- Adding DelegateControl reference to our custom SuiteSuiteLinksDelegate Control -->  
  4.         <Control ControlSrc="/_controltemplates/15/SuiteLinksDelegate_Example\MyCustomSuiteSuiteLinksDelegate.ascx" Id="SuiteLinksDelegate" Sequence="90" /> </Elements>  

Step 8: Final step is to build and deploy, then the SharePoint text will override with the Text of the portal.

The final outcome will look as in the following,

http://csharpcorner.mindcrackerinc.netdna-cdn.com/UploadFile/sagarp/implement-custom-suitelinks-delegate-control-in-sharepoint-2/Images/Menu.jpg