自定义 Sharepoint 中的页面视图
我自定义页面文档库中显示的字段(单击站点操作 - >所有站点内容 - >页面显示的表格)。
比我更了解共享点的人建议我也许应该在激活功能时以编程方式从默认视图中删除我不想要的字段,所以我编写了这段代码,感觉非常不优雅解决方案,也不起作用。
SPWeb web = properties.Feature.Parent as SPWeb;
if (web != null)
{
SPList list = web.Lists["Pages"] as SPList;
if (list != null)
{
foreach (SPField field in list.Fields)
{
if (field.Title != "Type" &&
field.Title != "Name" &&
field.Title != "Modified" &&
field.Title != "Checked Out To" &&
field.Title != "Page Layout")
{
if (list.DefaultView.ViewFields.Exists(field.InternalName))
{
list.DefaultView.ViewFields.Delete(field);
}
}
}
list.DefaultView.Update();
}
}
}
该代码肯定是在激活该功能时执行的,所以我显然做错了什么。 我已经找到了这个问题的解决方案,所以如果我错过了谷歌或这个网站上非常明显的东西,我深表歉意。
I'm customize the fields displayed in the Pages document library (the table displayed clicking site actions->all site content->pages).
It was suggested by someone who knows more about sharepoint than me that I should perhaps remove the fields which I didn't want from the default view programmatically on the activation of a feature, so I've written this code which feels like a very unelegant solution, and also does not work.
SPWeb web = properties.Feature.Parent as SPWeb;
if (web != null)
{
SPList list = web.Lists["Pages"] as SPList;
if (list != null)
{
foreach (SPField field in list.Fields)
{
if (field.Title != "Type" &&
field.Title != "Name" &&
field.Title != "Modified" &&
field.Title != "Checked Out To" &&
field.Title != "Page Layout")
{
if (list.DefaultView.ViewFields.Exists(field.InternalName))
{
list.DefaultView.ViewFields.Delete(field);
}
}
}
list.DefaultView.Update();
}
}
}
The code definately executed on activation of the feature so I'm obviously doing something wrong. I've searched for a solution to this so I apologise if I've missed something on google or this site which is blindingly obvious.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为对 list.DefaultView.ViewFields 的更改超出了范围。 在调用 Update() 之前,正在从数据库刷新集合。
尝试:
This is because the changes to list.DefaultView.ViewFields are going out of scope. The collection is being refreshed from the database before the call to Update() is reached.
Try: