如何从根网站及其所有子网站循环访问

发布于 2024-10-06 07:02:10 字数 47 浏览 0 评论 0原文

我遇到了一个需要解决的问题。我想循环访问根网站及其所有子网站,并希望设置一些属性

I came across a issue that I need to solve. I want to loop through a root web and all its subsites, and want to set some properties

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

物价感观 2024-10-13 07:02:10
    using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            using (SPSite oSPsite = new SPSite("http://sharepointdev:2021"))
            {
                using (SPWeb oSPWeb = oSPsite.OpenWeb())
                {
                    foreach (SPList list in oSPWeb.Lists)
                    {
                        if ( list.ContentTypes.Count > 0)
                        {

                            foreach (SPContentType contentType in list.ContentTypes)
                            {
                                if (contentType.Name == "Document")
                                {
                                    list.EnableModeration = true;
                                    list.Update();  
                                }
                            }
                        }
                    }

                    if(oSPWeb.Webs.Count > 0) 
                    recursivewebcheck(oSPWeb); 
                }
            }
        }



       static  void recursivewebcheck(SPWeb oSPWeb)
        {

            foreach (SPWeb web in oSPWeb.Webs)
            {
                foreach (SPList list in oSPWeb.Lists)
                {
                    if (list.ContentTypes.Count > 0)
                    {

                        foreach (SPContentType contentType in list.ContentTypes)
                        {
                            if (contentType.Name == "Document")
                            {
                                list.EnableModeration = true;
                                list.Update();
                            }
                        }
                    }
                }

                if (web.Webs.Count > 0)
                {
                    recursivewebcheck(web);
                }
                web.Dispose();
            }

        }
    }
}
    using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            using (SPSite oSPsite = new SPSite("http://sharepointdev:2021"))
            {
                using (SPWeb oSPWeb = oSPsite.OpenWeb())
                {
                    foreach (SPList list in oSPWeb.Lists)
                    {
                        if ( list.ContentTypes.Count > 0)
                        {

                            foreach (SPContentType contentType in list.ContentTypes)
                            {
                                if (contentType.Name == "Document")
                                {
                                    list.EnableModeration = true;
                                    list.Update();  
                                }
                            }
                        }
                    }

                    if(oSPWeb.Webs.Count > 0) 
                    recursivewebcheck(oSPWeb); 
                }
            }
        }



       static  void recursivewebcheck(SPWeb oSPWeb)
        {

            foreach (SPWeb web in oSPWeb.Webs)
            {
                foreach (SPList list in oSPWeb.Lists)
                {
                    if (list.ContentTypes.Count > 0)
                    {

                        foreach (SPContentType contentType in list.ContentTypes)
                        {
                            if (contentType.Name == "Document")
                            {
                                list.EnableModeration = true;
                                list.Update();
                            }
                        }
                    }
                }

                if (web.Webs.Count > 0)
                {
                    recursivewebcheck(web);
                }
                web.Dispose();
            }

        }
    }
}
箜明 2024-10-13 07:02:10
using (SPSite oSPsite = SpSecurityHelper.GetElevatedSite(GetSiteCollection(properties)))
        {
            SPWebCollection siteWebs = oSPsite.AllWebs;
            foreach (SPWeb web in siteWebs)
            {
                try
                {
                    SPList list = null;
                    try
                    {
                        list = web.Lists["Images"];
                    }
                    catch { }

                    if (list != null)
                    {

                        list.EnableModeration = isEnabled == false ? false: true;
                        list.Update();
                    }
                }
                finally
                {
                    if (web != null)
                        web.Dispose();
                }
            }
        }
using (SPSite oSPsite = SpSecurityHelper.GetElevatedSite(GetSiteCollection(properties)))
        {
            SPWebCollection siteWebs = oSPsite.AllWebs;
            foreach (SPWeb web in siteWebs)
            {
                try
                {
                    SPList list = null;
                    try
                    {
                        list = web.Lists["Images"];
                    }
                    catch { }

                    if (list != null)
                    {

                        list.EnableModeration = isEnabled == false ? false: true;
                        list.Update();
                    }
                }
                finally
                {
                    if (web != null)
                        web.Dispose();
                }
            }
        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文