Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am tryin to override the SiteMapProvider "CurrentNavigation" in nightandday.master. I got the code to override the class, but i am not sure how i handle the deploy process. A colleague told me that there is a way to deploy that using a "Feature" in VS2010. So i created a new Feature, bound CustomSitemapProvider.cs to it, and deployed everything.. As you probably expect now.. nothing changed. Do i have to change the Deployment Type? Or am i on the completely wrong track now?

Edit: I tried that with the Feature now... I got a elements.xml:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Control Id="AdditionalPageHead" Sequence="90" ControlAssembly="CustomSitemapProviderFeature, Version=1.0.0.0, Culture=neutral, PublicKeyToken=841c5c559877013a" ControlClass="CustomSitemapProviderFeature.CustomSitemapProvider"/>
</Elements>

And just a "Test Feature"..:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;

namespace CustomSitemapProviderFeature
{
    class CustomSitemapProvider : WebControl
    {

        protected override void OnLoad(EventArgs e)
        {
            string helloAlert = "alert('Hello, world!');";
            this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "popup", helloAlert, true);
            Label lab = new Label();
            lab.Text = "TEST";
            this.Page.Controls.Add(lab);

            base.OnLoad(e);
        }



    }
}

Well .. I am able to deploy that... but nothing happens... I am not able to run my code through a Feature... My plan is to override the whole SitemapProvider through such a class..

share|improve this question

1 Answer 1

up vote 0 down vote accepted

I haven't found a way to deploy a custom sitemap provider as a SharePoint feature.

I created an empty class library project in Visual Studio, added there my public class extending PortalSiteMapProvider, made the DLL available in the GAC, and manually added this line in the web.config file of the SharePoint web application, inside the <sitemap><providers> block:

<add name="CustomSiteMapProviderName" NavigationType="Current" type="_Fully qualified class name_, _Class library name without the dll extension_, Version=1.0.0.0, Culture=neutral, PublicKeyToken=_The key token for the dll_" />

In your class you need to override these two methods:

  • GetChildNodes - Here is where your custom business logic goes.
  • Initialize - To specify the name which will be used to identify your custom provider in the SiteMap.Providers collection. Something like this:

    public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config)
    {
        if (config == null)
            throw new ArgumentNullException("config is null");
    
        if (String.IsNullOrEmpty(name))
            name = "CustomSiteMapProviderName";
    
        if (string.IsNullOrEmpty(config["description"]))
        {
            config.Remove("description");
            config.Add("description", "Brief description");
        }
    
        base.Initialize(name, config);
    }
    

And then you can use your new provider in any navigation control.

share|improve this answer
    
Thank you Xavier for your answer but i really need a deployable solution for this.. –  fr34kyn01535 Oct 11 '11 at 13:01
    
Me too... so I kept looking, and today I found this: msdn.microsoft.com/en-us/library/ff649108.aspx It explains how to register the new provider in the section Configuring and Registering the Site Map Provider, by using the SPWebConfigModification class. –  Xavier Muñiz Oct 11 '11 at 16:56
    
Thank you, worked :D –  fr34kyn01535 Dec 15 '11 at 8:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.