Binding Web Application, Site Collection, Sites and Library data to a Sharepoint 2007 dropdown list in a web part
A. I'd like to know the best way to retrieve the web applications, site collections, sites and libraries of a SharePoint 2007 install (on a farm) and display each of those data in a dropdown list of their ow开发者_开发问答n a web part.
B. What type of web part should be used
C. What object model or database/tables do I get those pieces of information from
For example:
"Web Applications" Dropdownlist1
"Site Collections" Dropdownlist2
"Sites" Dropdownlist3
"Libraries" in a scrollable Textarea
SPFarm farm = SPFarm.Local;
SPWebService service = farm.Services.GetValue<SPWebService>("");
foreach (SPWebApplication webapp in service.WebApplications)
{
foreach (SPSite sitecoll in webapp.Sites)
{
foreach (SPWeb web in sitecoll.AllWebs)
{
<<Use recursion here to Get sub WebS>>
web.Dispose();
}
sitecoll.Dispose();
}
}
the above code sample provides code to find listing of all webs in a spfarm you can use the above sample to find all webapplication, sitecollection, webs, use SPListto get all list item from splistcollection available in SPweb.lists
If you want to display each type of data in each drop down list in each own Web part. You can make some connected Web parts.
For example:
1- The Web application list Web part
You can get the data from SPWebService.WebApplications
. The selected Web application should be used as the filter for the Site collection list Web part.
2- The Site collection list Web part.
You can get the data from SPWebApplication.Sites
. The selected Site should be used as the filter for the Web list Web part. Ensure to dispose the SPSite
object after using it.
3- Web list Web part.
You can get the data from SPSite.AllWebs
. Ensure to dispose the SPWeb
object after using it.
精彩评论