SharePointCommunity
Die deutschsprachige Community für SharePoint, Microsoft 365, Teams, Yammer und mit Azure
SharePoint - Create a QuickLaunch heading by code

Blogs

Oliver Wirkus

Syndication

Certifications

Web 2.0

http://smits-net.de/img/linkedin_button.gif

XING

http://i80.photobucket.com/albums/j191/mikesamerica/twitter_button_zpsee74f711.png

 

 Add to Technorati Favorites

 

 Delicious Bookmark this on Delicious

 

  Locations of visitors to this page

 

There was just one task left to complete a SharePoint development project. Just a few custom QuickLaunch items that should be created when a certain feature has been turned on. ‘No big deal' - just playing around with some SPNavigationNode objects’ - that was what I thought.

So I started with the first QuickLaunch heading. My heading shouldn’t have an url. Therefore I used these lines of code:

image

image

I set the second parameter to string.Empty because I didn’t want my heading to have an url. What I wanted was just a plain simple QuickLaunch navigation heading - just the like the ones that can be created using this dialog:

image

Looks pretty easy, but when I pressed F5 in Visual Studio to check if these lines of code create my heading, this is what I saw:

image

Although the second parameter of the SPNavigationNode constructor has been set to string.Empty, my heading had an url. It was the base url of the site collection. After I changed the last parameter from true to false (or even used the two-params constructor instead) the heading wasn’t even created. This was not the correct way to create a QuickLaunch heading.

To understand why I had to dive deeper in the properties of the SPNavigationNode object. So I opened MSDN and looked for the members of the SPNavigationNode object. Although there have been a lot of properties and methods there was nothing to mark a SPNavigationNode as heading.

Fortunately I found the blog of Koen van der Linden and he published a post about how to create a QuickLaunch heading by code. He ran into the same problem and like me didn’t found a solution by looking at the SPNavigationNode object’s properties or methods.

To create a QuickLaunch heading you need to change some ‘hidden’ parameters in a SPNavigationNode object. Simply set the property ‘NodeType’ to ‘Heading’. To set or change these ‘hidden’ properties you need to access the ‘Properties’ collection of the SPNavigationNode object.

Here is the link to Koen’s post with the full story: http://kvdlinden.blogspot.de/2011/02/add-spnavigation-heading-to-quicklaunch.html

Thanks to Koen for publishing this :-)

Add to Technorati Favorites Folge mir auf Twitter FourSquareLogo

Bereitgestellt 19 Feb 2013 12:51 von Oliver Wirkus
Gespeichert unter: , ,