列表属性未更新

发布于 2024-10-06 12:05:15 字数 890 浏览 0 评论 0原文

我在 SiteCollection 的每个网站 (SPWeb) 上都有一个图像列表。我想设置此列表的特定属性。我正在迭代 SiteCollection 中的所有站点并查找列表并设置其属性。我的问题是,我可以设置第一级站点上存在的列表的属性,但无法设置第二级或第三级站点上存在的列表的属性。例如,

以下是站点层次结构:

首页 (Rootweb) 第一级

首页->关于我们(子网站)第二级

主页->关于->我们的使命(子网站)第三级

是代码!

using (SPSite oSPsite = new SPSite(http://spdev/))
{                
    foreach (SPWeb web in oSPsite.AllWebs)
    {
        SPList list = web.GetList("PublishingImages");
        if (list != null)
        {
            foreach (SPContentType contentType in list.ContentTypes)
            {
                if (contentType.Name == "Publishing Picture")// but id is better
                {
                    list.EnableModeration = false;
                    list.Update();
                }
            }
        }
        web.Dispose();
    } 
}                 

是因为我先处理了父母吗?

I have an Image List on each and every web (SPWeb) of a SiteCollection. I want to set a specific property of this List. I am iterating through all the Sites withing a SiteCollection and finding the List and setting its properties. My problem is that I can set the properties of a List present at first level Sites, but can't set the properties of Lists, present at 2nd or 3rd level Sites. For example,

Here is site hierarchy:

Home (Rootweb) 1st level

Home-> Aboutus (subsite) 2nd level

Home->Aboutus->Our Mission (subsite) 3rd level

here is the code for that!

using (SPSite oSPsite = new SPSite(http://spdev/))
{                
    foreach (SPWeb web in oSPsite.AllWebs)
    {
        SPList list = web.GetList("PublishingImages");
        if (list != null)
        {
            foreach (SPContentType contentType in list.ContentTypes)
            {
                if (contentType.Name == "Publishing Picture")// but id is better
                {
                    list.EnableModeration = false;
                    list.Update();
                }
            }
        }
        web.Dispose();
    } 
}                 

Is it because I'm disposing the parent first?

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

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

发布评论

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

评论(1

一片旧的回忆 2024-10-13 12:05:15

假设每个站点 (PublishingImages) 上的列表名称都相同,并且您使用的是 WSS 3.0 或 MOSS07,这里是示例代码:

using (SPSite oSPsite = new SPSite("yourSiteUrlHere"))
{
    SPWebCollection siteWebs = oSPsite.AllWebs;
    foreach (SPWeb web in siteWebs)
    {
        try
        {               
            SPList list = null;
            try
            {
                list = web.Lists["PublishingImages"];
            }
            catch {}

            if (list != null)
            {
                // todo: update list properties here
                list.Update();
            }
        }
        finally
        {
            if(web != null)
                web.Dispose();
        }
    }  
}

正如 Asutosh 提到的,有一些属性不适用于所有列表类型,但我假设因为您已经声明它适用于其中一些,所以您没有设置其中任何一个。

Assuming the list name is the same on every site (PublishingImages) and you're on WSS 3.0 or MOSS07 here is the sample code:

using (SPSite oSPsite = new SPSite("yourSiteUrlHere"))
{
    SPWebCollection siteWebs = oSPsite.AllWebs;
    foreach (SPWeb web in siteWebs)
    {
        try
        {               
            SPList list = null;
            try
            {
                list = web.Lists["PublishingImages"];
            }
            catch {}

            if (list != null)
            {
                // todo: update list properties here
                list.Update();
            }
        }
        finally
        {
            if(web != null)
                web.Dispose();
        }
    }  
}

As Ashutosh mentioned, there are some properties that don't work on all list types but I'm assuming since you've already stated it works on some of them you aren't setting any of those.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文