开发者

How to get all sites and sub-sites in SharePoint and access an image library/list?

How to get all sites and sub-sites in SharePoint and access an image library/list?

I am looking forward to achieve this via the SharePoint object model. Inside each site or subsite I w开发者_如何学Goant to access an image library/list,

How to get all sites and sub-sites in SharePoint and access an image library/list?

After getting to this list, how do I set the option of 'Required Content Approval for Selected Items' from 'Yes' to 'No'?


Use the SPFarm object to get all web applications then use SPWebApplication to get all sitecollection and then use SPSite to get all Webs.

You have to loop through all three to get all sites under the site collection. If you want to find subsites under spweb please call all spwebs recursively until you don't find any webs under spweb for each spweb.

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();
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜