Get the SharePoint Hierachy Through Sharepoint Object Model

What you actually need to do, is always check the property ParentWeb if you are in a subsite, if you are in a list check your site.
Put all this information in a stringbuilder object, and so you are going to construct your breadcrumb or any other string. SPNavigation will provide you the values you have customized in the sharepoint site.

Because that is what you are asking, the code for creating your own breadcrumb.

string HBX_mlc;
using (SPSite Mysite = new SPSite(url))
{
using (SPWeb web = Mysite.OpenWeb())
{
getlist(web);
str.Reverse();

foreach (string value in str)
{
HBX_mlc += value;
Response.Write(value);
}
}
}
void getlist(SPWeb web)
{
if (web.IsRootWeb == true)
{
str.Add(web.Title);
}
else
{
str.Add(web.Title);
str.Add("/");
getlist(web.ParentWeb);
}
}

 

And to get the list name from the url after opening the spweb
web.GetListFromUrl(url))
And then to get the list view type from the url
web.GetViewFromUrl(url))

A better version using the SPContext is as follows.
string HBX_MLC;
using (SPWeb web = SPContext.Current.Web)
{
getlist(web);
str.Reverse();
foreach (string value in str)
{
HBX_MLC += value;
}
if (SPContext.Current.List.Title != null)
{
HBX_MLC += SPContext.Current.List.Title;
HBX_ViewName = "List View : " + SPContext.Current.ViewContext.View;
}
}
void getlist(SPWeb web)
{
if (web.IsRootWeb == true)
{
str.Add(web.Title);
}
else
{
str.Add(web.Title);
str.Add(" / ");
getlist(web.ParentWeb);
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *

Bitnami