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

穿精又带淫゛_ 提交于 2019-12-11 05:04:08

问题


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,

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


回答1:


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


来源:https://stackoverflow.com/questions/4344187/how-to-get-all-sites-and-sub-sites-in-sharepoint-and-access-an-image-library-lis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!