Monday, June 06, 2011

Accessing SharePoint Publishing site Navigation (Global Navigation bar) using C#

Accessing SharePoint Publishing site Navigation (Global Navigation bar) using C#:

With the help of PublishingWeb class (Microsoft.SharePoint.Publishing), we can access different components of Published Web site like Pages document library, Published site navigation bar and etc.
In this example we will access different components of Published site:


using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Office.Server;
using Microsoft.Office.Server.Administration;
using Microsoft.Office.Server.UserProfiles;
using Microsoft.SharePoint;
using System.Web;
using Microsoft.SharePoint.Navigation;
using Microsoft.SharePoint.Publishing;


namespace GetPublishedData
{
class Program
{
static void Main(string[] args)
{

using (SPSite site = new SPSite("http://amitkumarmca04.blogspot.com/"))
{
using (SPWeb web = site.RootWeb)
{
PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web);

//Display Global Navigation menu items(Home > Site Settings > Modify Navigation)
foreach (Microsoft.SharePoint.Navigation.SPNavigationNode node in publishingWeb.GlobalNavigationNodes)
{

Console.WriteLine(node.Title + " " + node.Url);

}
// Get the Id for the Pages list.
Guid pagesListId = publishingWeb.PagesListId;
SPList pagesList = publishingWeb.PagesList;

// The PublishingWeb.PagesListName is equivalent
// to PublishingWeb.PagesList.RootFolder.Url.
string pagesListUrl = publishingWeb.PagesListName;

}
}
}
}
}


Reference: MSDN
Share:

1 comments:

sbobet said...

thanks ysboou for arsbochive

Sitecore® Technology MVP 2019

Featured Post

Sitecore Error Troubleshooting: Sitecore Solr Connectivity Issue:: Part-1

Sitecore Error Troubleshooting: Sitecore Solr Connectivity Issue:: Part-1 How to verify Sitecore 9.1 (IaaS and Azure PaaS) + Solr (IaaS) C...

Total Pageviews

State Counder

Popular

About Me

My photo
Based in Bangalore, INDIA, Amit is a Sitecore MVP and MCC. He has an MCA from the U.P.T.U., INDIA and holds certifications including Sitecore and SharePoint 2007/2010. He is an contributor to Sitecore/MSDN communities and http://amitkumarmca04.blogspot.com/. Amit have experience in Sitecore, ASP.Net with C#, MVC, SharePoint, Classic ASP, VB,Macros,HTML,JavaScript,JSON,BootStrap and AngularJS.

Followers

Follow me on Twitter

Labels