Archive

Posts Tagged ‘Navigation’

Customization of SharePoint 2010 navigation – publishing site

February 12th, 2010 2 comments

In my previous blog, I customized the SharePoint 2010 publishing site. Now I will give you some idea that how you can create customize the navigation according to new look and feel. There are different ways to customize the navigation of SharePoint. I like to use a custom control which returns navigation in the form of xml and then I transform it from xsl. In this way you can easily control the output of the navigation or any other control.  

<SafeControl Assembly=SalmanSPControls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=49908bd985021621 Namespace=SalmanSPControls TypeName=* Safe=True />You need to add a reference in your SharePoint master page. It would be like this. 

<% @ Register Tagprefix=”SWC” Namespace=”SalmanSPControls” Assembly=”SalmanSPControls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=49908bd985021621″ %>  

Then I created a class for navigation inherited from ASP .Net Menu and xml based control class. This class is not doing much but just adding all the items in xml. It’s getting these items from Menu items. In the master page when you use this control you need to specify the data source id. If you search in your master page you can find a tag like this.  

<PublishingNavigation:PortalSiteMapDataSource EnableViewState=”false” ID=”leftNavDataSource” Runat=”server” SiteMapProvider=”CombinedNavSiteMapProvider” StartFromCurrentNode=”true” StartingNodeOffset=”1″ ShowStartingNode=”true” TreatStartingNodeAsCurrent=”true” TrimNonCurrentTypes=”Heading” />  

There will be two tags like above one for global navigation and other for current navigation. For left navigation you have to look the current navigation site map data source. In portal site map data source you can also change the SiteMapProvider, depending on your needs. You can use the current or combine or global. These site map providers are defined in web.config. You can find the difference of these site map providers in SharePoint documentation.
Now you have to replace the existing navigation control with your new custom navigation control. After that your master page changes are over. Now your control is ready and will display instead of default SharePoint current navigation. Here is how your navigation control will look like.  

<SWC:Navigation cacheperpage=”true” EnableViewstate=”false” ID=”LeftNav” Runat=”server” DataSourceID=”leftNavDataSource” Transform-XslName=”leftnav.xsl” Transform-CacheOutput=”false”/> 
 
But this control is just returning xml. You need to transform it in an html through some xsl. For this I created one xsl file and use some style classes to give it new look.  Here is the piece of code I use in my xsl to transform navigation xml into new look. 
 
<xsl:template match=”/>
    <xsl:if test=count(Navigation/Item) &gt; 0>
        <div id=nav-y>
             <p>
                 <a href={Navigation/Item/@Url}title=”{Navigation/Item/@Title}>
                      <xsl:value-of select=”Navigation/Item/@Titledisable-output-escaping=”yes/>
                 </a>
             </p>
             <ul>
                 <xsl:apply-templates select=”Navigation/Item>
                     <xsl:with-param name=”levelselect=”1/>
                     <xsl:with-param select=”@Titlename=”sectionTitle/>
                 </xsl:apply-templates>
              </ul>
        </div>
    </xsl:if>
 </xsl:template>
 
<xsl:template match=”Item“>
    <xsl:param name=”level” />
    <xsl:param name=”sectionTitle” />
    <xsl:choose>
        <xsl:when test=”$level != 1“>
            <li>
                <xsl:if test=”@Selected=’True’ or @Current=’True“>
                    <xsl:attribute name=”class“>Selected</xsl:attribute>
                </xsl:if>
                <a href=”{@Url}title=”{@Title}“>
                    <xsl:value-of select=”@Titledisable-output-escaping=”yes“/>
                </a>
                <xsl:if test=”count(Item) &gt; 0 and @Current = ‘True“>
                    <ul>
                        <xsl:apply-templates select=”Item“>
                            <xsl:with-param name=”levelselect=”$level + 1” />
                            <xsl:with-param select=”@Titlename=”sectionTitle” />
                        </xsl:apply-templates>
                    </ul>
                </xsl:if>
            </li>
        </xsl:when>
        <xsl:otherwise>
            <xsl:apply-templates select=”Item“>
                <xsl:with-param name=”levelselect=”$level + 1” />
                <xsl:with-param select=”@Titlename=”sectionTitle” />
            </xsl:apply-templates>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>
 
 So now after doing all these changes my new site will look like this.
  
   

Hope you enjoyed customization of SharePoint 2010 navigation in publishing sites.  

Cheers

Using SharePoint site Navigation to a non-SharePoint website

October 5th, 2009 Comments off

It was a very interesting task we had from one client. We had developed a publishing internet site for the same client. This client has a non SharePoint site, somehow this non SharePoint site has a relation with SharePoint site and client wanted to provide an option to navigate to other site from publishing SharePoint site. The interesting thing was client wanted to have the same look and feel for other site as of SharePoint site, specially client wanted to have the same left navigation. So when users navigate from SharePoint site to non SharePoint site they don’t get the feeling that now they are on a different website.

We have tried to think in different ways to implement this option. But there was no straight forward way to use the SharePoint navigation in a non SharePoint site. After giving it some thought we suggested something pretty simple, which looked difficult in initial talks.

We have created a web service, which interact with SharePoint. This web service actually makes a request to the same page from SharePoint website, from where we have to use the left navigation. Then it grab the whole html and use xpath to extract the div with navigation part. It just return this extracted html as xml.
Now we call this web service from the non SharePoint website and fill the left part with returned div from web method used in web service. It seems pretty simple 
We used the same technique to change the whole look and feel for the non SharePoint site to match the SharePoint site. And it worked great.

Here is the piece of code from web service.

[WebMethod(Description = "pageType should be one of pre-defined page type.")]

public XmlDocument GetLeftNavigation(string pageType)

{

  XmlDocument oDoc = new XmlDocument();

  oDoc.LoadXml(“<rows/>”);

  string html = “”;

  if (ConfigurationManager.AppSettings[pageType] != null)

  {

    string url = ConfigurationManager.AppSettings[pageType];

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

    request.Method = “GET”;

    request.Credentials = CredentialCache.DefaultCredentials;

    HttpWebResponse response = (HttpWebResponse)request.GetResponse();

 

    try

    {

      if (response.StatusCode == HttpStatusCode.OK)

      {

        // get the response stream.

        Stream responseStream = response.GetResponseStream();

        // use a stream reader that understands UTF8

        StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);

        try

        {

          html = reader.ReadToEnd();

          html = html.Substring(html.IndexOf(“<div id=\”nav-y\”>”));

          html = html.Remove(html.IndexOf(“</li></ul></div>”) + 16);

          oDoc.LoadXml(html);

          if (oDoc.GetElementsByTagName(“a”).Count > 0)

          {

            string siteUrl = ConfigurationManager.AppSettings["webpath"];

            foreach (XmlNode oNode in oDoc.GetElementsByTagName(“a”))

            {

              string href = oNode.Attributes["href"].Value;

              href = siteUrl + href.Substring(1);

              oNode.Attributes["href"].Value = href;

            }

          }

        }

        catch (Exception ex) { }

        finally

        {

          // close the reader

          reader.Close();

        }

      }

    }

    finally

    {

      response.Close();

    }

  }

  return oDoc;

}

Hope you will like it.

Cheers

Categories: MOSS Tags: , ,

Role of DynamicChildLimit in MOSS Navigation

June 2nd, 2009 59 comments

Recently, we were working on a project where pages libraries has hundreds of pages. We have noticed that in left navigation and on modify navigation pages, it was not showing all the pages. Actually, MOSS navigation site map providers returned 50 items by default. if you want to see all the pages, you need to set the PortalSiteMapProvider property of DynamicChildLimit = 0 in web.config.

It will be like this

<add name=”CurrentNavSiteMapProvider” description=”CMS provider for Current navigation” type=”Microsoft.SharePoint.Publishing.Navigation.PortalSiteMapProvider, Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” NavigationType=”Current” EncodeOutput=”true” DynamicChildLimit=”0″ IncludePages=”PerWeb” IncludeHeadings=”true” IncludeAuthoredLinks=”true” />

 

Referenced from Chris Richard’s blogs Increased performance for MOSS apps and MOSS Navigation Deep-Dive .

Categories: MOSS Tags: , ,