Introduction:
Here we will discuss how to retrieve all sites and subsites under site collection using SharePoint object model. In our previous articles we have seen how we can get user profile details using SharePoint 2010 object model.
Description:
To retrieve all sites and sub sites presented within a site collection we can use SharePoint 2010 object model classes. Also we can do it through client object model which was introduced in SharePoint 2010.
Below is the code to retrieve all the details:
using (SPSite spsite = new SPSite(HttpContext.Current.Request.Url.ToString())) {
using (SPWeb spweb = spsite.OpenWeb())
{
SPWebCollection spWebColl = spweb.GetSubwebsForCurrentUser();
foreach (SPWeb spChildWeb in spWebColl)
{
Response.Write(spChildWeb.Title + spChildWeb.Url + "");
}
}
}
Here GetSubwebsForCurrentUser() method is responsibe to return the collection of subsites under the current site of which the current user is a member.
Also you can check some SharePoint 2010 server object model.
Here we will discuss how to retrieve all sites and subsites under site collection using SharePoint object model. In our previous articles we have seen how we can get user profile details using SharePoint 2010 object model.
Description:
To retrieve all sites and sub sites presented within a site collection we can use SharePoint 2010 object model classes. Also we can do it through client object model which was introduced in SharePoint 2010.
Below is the code to retrieve all the details:
using (SPSite spsite = new SPSite(HttpContext.Current.Request.Url.ToString())) {
using (SPWeb spweb = spsite.OpenWeb())
{
SPWebCollection spWebColl = spweb.GetSubwebsForCurrentUser();
foreach (SPWeb spChildWeb in spWebColl)
{
Response.Write(spChildWeb.Title + spChildWeb.Url + "");
}
}
}
Here GetSubwebsForCurrentUser() method is responsibe to return the collection of subsites under the current site of which the current user is a member.
Also you can check some SharePoint 2010 server object model.