如何在我的 SharePoint 网站中获取多个同名列表?
我有一个根据自定义网站定义创建的 SharePoint 网站。 站点定义具有以下功能:
- 自定义内容类型。
- 自定义列表模板,其 schema.xml 文件引用该内容类型。
- 列表实例功能指的是我上面的列表模板功能。
在站点配置过程中,我按照上面的顺序通过 C# 代码激活每个功能(每个功能都在 SPWeb 级别)。 我生成的网站看起来如我所料,并且似乎工作正常,但它有一个奇怪的现象,即我网站的“所有网站内容”页面显示了我的自定义列表两次。
我的列表表现良好 - 它的项目接收器正确触发并且仅触发一次。 在 SharePoint Manager (SPM) 中,我还看到该列表显示两次,当我展开树时查看属性,它们在两个列表中看起来相同(甚至列表内的列表项)。 我怀疑我可能在欺骗自己,SPM 可能只是查看同一个列表两次,而一些实际的流氓列表位于我网站的黑暗阴影中。
那么,这里可能出了什么问题呢? 我如何创建多个同名列表? 我怎样才能正确创建这个列表? 我怎样才能正确地清理现有网站中表现出这种行为的奇怪现象?
编辑: 为了回答 Michael Stum 的问题,我创建了这个控制台应用程序来循环访问网站的列表并获取 ID:
using (SPSite site = new SPSite("http://myserver/projects/myproject"))
{
using (SPWeb web = site.OpenWeb())
{
var lists = web.Lists;
foreach (SPList list in lists)
{
Console.WriteLine(list.ID + ": " + list.Title);
}
}
}
此代码显示我的列表两次 - 相同的标题、相同的 ID。
另一个编辑: 我查看了该网站的 SharePoint 内容数据库,并执行了以下查询:
SELECT * FROM AllLists where tp_webid = '<my SPWeb guid>'
这表明只有一个实际列表,其标题和 GUID 是我从上面的 C# 代码中检索到的。 那么,是什么导致我在浏览网站时出现这些多个条目呢?
I have a SharePoint site that's being created from a custom site definition. The site definition has the following Features:
- A custom content type.
- A custom list template whose schema.xml file refers to that content type.
- A list instance feature which refers to my above list template feature.
During the site provisioning process, I activate each of these features (each is at the SPWeb level) through C# code in the order above. My resulting site looks as I expect and seems to work fine, but it has the weird artifact that the "all site content" page for my site shows my custom list twice.
My list acts okay -- its item receivers fire correctly and only once. In SharePoint Manager (SPM), I also see the list show up twice, and when I expand the tree to look at the attributes, they appear identical across the two lists (even the list items inside the lists). I suspect that I may be fooling myself and SPM might be just looking at the same list twice, while some actual rogue list lies in the dark shadows of my site.
So, what could have gone wrong here? How could I have created multiple lists of the same name? How can I correctly create this list? And how can I properly clean up the weirdness in existing sites that exhibit this behavior?
Edit:
In response to Michael Stum's question, I created this console app to loop through the site's lists and get the ID:
using (SPSite site = new SPSite("http://myserver/projects/myproject"))
{
using (SPWeb web = site.OpenWeb())
{
var lists = web.Lists;
foreach (SPList list in lists)
{
Console.WriteLine(list.ID + ": " + list.Title);
}
}
}
This code shows my list twice -- same title, same ID.
Another edit:
I looked in the SharePoint content database for this site, and I executed this query:
SELECT * FROM AllLists where tp_webid = '<my SPWeb guid>'
This reveals that there's only one actual list with the title and GUID that I retrieved from my C# code above. So what is causing these multiple entries to show up when I'm browsing through my site?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我已经多次遇到过这个问题。 这不是一个错误,很可能是您的列表模板的 elements.xml 中存在语义错误。
如果列表定义包含多个默认视图,则会出现您上面描述的症状。 检查列表模板的 elements.xml 文件,并确保其中没有多个视图元素。
亲切的问候
拉蒙
I've come across with this issue several times. It's not a bug, most likely you have semantic errors in the elements.xml of your list template.
If a list definition contains more than one default view, the symptoms you described above will show up. Check the elements.xml file of your list template and make sure you don't have more than one View-Element with in it.
Kind regards
Ramon
我建议你给微软打电话,这听起来像是一个错误。
PS,如果没有看到创建列表的实际解决方案,我们无法确定发生了什么,也许某个功能被激活了两次......
I suggest you put a call in to Microsoft, this sounds like a bug.
P.S. without seeing the actual solution that creates the list we can't determine what's happening, perhaps a feature got activated twice...
今天我遇到了这个问题,在阅读上述答案后,我想出了一个简单的解决方案。 只需创建一个新的默认视图,文档库就会再次正常显示。
亲切的问候,
Thijmen Groenewegen
P.s
我通过将库从一个地方迁移到另一个地方来“创建”相同的两个库。 在老地方,图书馆只展示过一次。 如果我查看该库的默认视图,则有两个视图被检查为默认视图。
Today I came across this issue and after reading the above answers I came up with an easy solution. Just create a new Default view and the Document library will show up normally again.
Kind regards,
Thijmen Groenewegen
P.s
I "created" the same two libraries by migrating the library from one place to another. At the old place the library was only showed once. If I look at the default views on that library two views are checked as Default.
格罗内韦根 (Groenewegen) 恰到好处。
在子网站上运行 Export-SPWeb,然后运行 Import-SPWeb 将其移动到新网站集后,我最终在网站上得到了两个公告列表。
为了解决这个问题,我为列表创建了一个新的默认视图“所有列表项”,选择两个“所有项目”视图之一并将其删除,问题就得到了解决。
公告列表在“查看所有网站内容”页面上显示两次,并且在查看“所有项目”页面时数据显示两次。
此外,在创建新的默认视图之前必须执行的中间步骤是打开列表或库并将“?contents=1”添加到 URL,以便您可以打开 Web 部件维护页面并“关闭”其中之一重复项。 您必须执行此操作,因为如果存在多个 Web 部件,Web 部件功能区将不会显示在“公告”页面上,并且您需要功能区来访问视图下拉列表并创建新视图。
Groenewegen is spot on.
I ended up with two Announcements lists on a site after I ran Export-SPWeb on a subsite and then Import-SPWeb to move it to a new site collection.
To fix it, I created a new default view for the list, All List Items, selected one of the two All Items views and deleted it, and the issue was fixed.
The Announcements list was being displayed twice on the View All Site Content page, and the data was being shown twice when viewing the All Items page.
Also, an intermediate step that you have to take before creating a new default view, is to open the list or library and add "?contents=1" to the URL so you can open the web part maintenance page and "Close" one of the duplicates. You have to do this because the web part ribbon will not show up on the Announcements page if multiple web parts exist, and you need the ribbon to access the view drop down and create a new view.
您是否尝试过:
list.RootFolder.Name
(显示“内部”名称 - 网址的一部分)
list.Title 显示显示名称(可以出现两次或更多次)。
这也可以解释为什么你会得到多个列表。 您可能添加了具有相同显示名称但不同“内部”名称的它们?
Have you tried with:
list.RootFolder.Name
(which shows the "internal" name - a part of the url)
list.Title shows the displayname (which can appear twice or more).
This could also be the explanation why you get multiple lists. You have maybe added them with the same displayname but dirrerent "internal" names?