tags:

views:

128

answers:

1

Hi all,

Background in TFS whenever you create a new project, a new SharePoint site is created under http://sharepoint/sites/projectname. To see those subsites, the following is the link that describe it:

http://blog.aggregatedintelligence.com/2009/04/viewing-list-of-tfs-portals-in.html

Now I want to create a SharePoint webpart that retrieve all of the projects under http://sharepoint/sites. I use the following method:

        using (SPSite site = new SPSite("http://sharepoint/sites/"))
        {

            foreach (SPWeb web in site.AllWebs)
            {
                //do operations here
            }
        }

Now the thing is that it doesn't work. The site does not retrieve the sites under those directories. How do I do that?

A: 

I'd expect that the reason you're not getting anything back is because /sites/ isn't really a site collection on SharePoint, which you'd notice if you try and access /sites/ as a path on the SharePoint server.

You'll probably have to just return all the sites from the root web and then just filter on the path name whether or not it contains /sites/. I believe that is how Central Administration displays the list of sites within the web application list.

Slace
Yeah I did that, but the thing is it requires 'account operates as system' permission. Is there a way so that we dont need to grant that access to all user accessing the site?foreach(SPSite s in wa.Sites) { using(SPSite site = s) { foreach (SPWeb web in site.RootWeb.GetSubwebsForCurrentUser()) { if (web.Url.Contains("/Sites/")) { //do things here } } } }
A retype of the code above:SPWebApplication wa = SPWebApplication.Lookup(new Uri("http://sharepoint")); foreach(SPSite s in wa.Sites) { using(SPSite site = s) { foreach (SPWeb web in site.RootWeb.GetSubwebsForCurrentUser()) { if (web.Url.Contains("/Sites/")) { //do things here } } } Controls.Add(table); }
ah found the answer: RunWithElevatedPrivileges