如何获取 SharePoint 中的所有站点和子站点并访问图像库/列表? [英] How to get all sites and sub-sites in SharePoint and access an image library/list?

查看:58
本文介绍了如何获取 SharePoint 中的所有站点和子站点并访问图像库/列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取 SharePoint 中的所有站点和子站点并访问图像库/列表?

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

我期待通过 SharePoint 对象模型实现这一目标.在每个站点或子站点中,我想访问图像库/列表,

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'?

推荐答案

使用 SPFarm 对象获取所有 Web 应用程序,然后使用 SPWebApplication 获取所有站点集合,然后使用SPSite 获取所有网站.

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

您必须遍历所有三个以获取网站集下的所有网站.如果您想在 spweb 下查找子站点,请递归调用所有 spweb,直到在每个 spweb 下都找不到任何站点为止.

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

这篇关于如何获取 SharePoint 中的所有站点和子站点并访问图像库/列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆