Peter O'Brien

This seems like a simple question but I've trawled the net and not found a simple answer.

If I have a site on Sharepoint Server 2007 (Enterprise edition), and I create a few new subsites and workspaces, is there a web part that will show all subsites Or do I have to add individual links manually for each of the subsites to a list and then display the list through a webpart

Re: Sharepoint Web Parts for Subsites

MS ISV Buddy Team

Hi Peter,

Here's some info from our support engineer that may help:

I am working on this issue at present. I could not find any Out of the Box webpart which lists subsites. But I wrote a sample code for a webpart which will do the same. I am attaching the project in zipped format and also listing the code in the email body.


using System;

using System.Runtime.InteropServices;

using System.Web.UI;

using System.Web.UI.WebControls.WebParts;

using System.Xml.Serialization;

using Microsoft.SharePoint;

using Microsoft.SharePoint.WebControls;

using Microsoft.SharePoint.WebPartPages;

namespace ListSubSites



public class ListSubSites : System.Web.UI.WebControls.WebParts.WebPart


string output = "<table border=\"0\">";

protected override void CreateChildControls()



SPSite site = new SPSite("http://pranab-sec/");

SPWeb web = site.OpenWeb();

SPWebCollection subSites = web.Webs;

foreach (SPWeb subSite in subSites)


output += "<tr><td><a href=\"" + subSite.Url + "\"/>" + subSite.Title + "</a></td></tr>";


output += "</table>";


protected override void Render(HtmlTextWriter writer)


// TODO: add custom rendering code here.







-brenda (ISV Buddy Team)

Re: Sharepoint Web Parts for Subsites


I'm new to sharepoint and I'm not much of a coder either Sad How do I make this into a dwp file which I can upload to WSS 3.0

Thanks in advance for your help...

Re: Sharepoint Web Parts for Subsites


Thank you so much for tht codes..

tht was really helpful to me..

Re: Sharepoint Web Parts for Subsites


Hi stubzy,

You dont have to do much to create the dwp file.

Hope u know to make it as a safe assemby,doing the modifications in web.config file.

Afte u're done with that. u can go to the top level site's site settings- webparts gallery- click on new

There u shud be able to view the webpart assembly you created. check the box next to it and click on populate.

now u can go to ur website and add that webpart which will be listed in the miscellaneous sections.

thank you,