列表属性未更新
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设每个站点 (PublishingImages) 上的列表名称都相同,并且您使用的是 WSS 3.0 或 MOSS07,这里是示例代码:
正如 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:
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.