문제

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 want to access an image library/list,

alt text

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();
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top