Logo 
Search:

MOSS Forum

Ask Question   UnAnswered
Home » Forum » MOSS       RSS Feeds

Displays all site collections in a farm

  Asked By: Joshua    Date: Sep 09    Category: MOSS    Views: 11201

Is there a way to make a webpart that that displays all site collections in a farm?? Im trying to easily figure this out.

Thanks!

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Peter paul Kirschner     Answered On: Sep 10

You can Try this

protected override void CreateChildControls()
{
base.CreateChildControls();
SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPServiceCollection services = SPFarm.Local.Services;
foreach (SPService curService in services)
{
if (curService is SPWebService)
{
SPWebService currentwebservice =(SPWebService) curService;
foreach (SPWebApplication webapp in currentwebservice.WebApplications)
{
//get all Sites from webapp
foreach (SPSite site  in webapp.Sites)
{
this.Controls.Add(new Literal() { Text = "SiteUrl "+site.Url });
using (SPWeb rootweb = site.RootWeb)
{
this.Controls.Add(new Literal() { Text = "RootWebUrl: " + rootweb.Url });
this.Controls.Add(new Literal() { Text = "Title: " + rootweb.Title });
}

if (site != null)
site.Dispose();
}
}
}
}

});
}

 
Answer #2    Answered By: Esha Attlee     Answered On: Sep 11

To return the collection of The all the Webs or sites within a site  collection, including the top-level site and all subsites.

SPSite oSiteCollection = SPContext.Current.Site;
using(SPWebCollection collWebsite = oSiteCollection.AllWebs);
{

for (int i = 0; i < collWebsite.Count; i++)
{
using (SPWeb oWebsite = collWebsite[i])
{
SPListCollection collList = oWebsite.Lists;

for (int j = 0; j < collList.Count; j++)
{
Label1.Text += SPEncode.HtmlEncode(collWebsite[i].Title) + ” ”
+ SPEncode.HtmlEncode(collList[j].Title) + “<BR>”;
}
}
}
}

Read the full article @ www.learningsharepoint.com/.../

 
Didn't find what you were looking for? Find more on Displays all site collections in a farm Or get search suggestion and latest updates.




Tagged: