将列表项从主列表复制到子站点

发布于 2024-08-28 08:04:54 字数 275 浏览 15 评论 0原文

我有一个包含自定义列表大师的网站。我有许多子站点,其中包含此列表的副本。当有人编辑新列表项或将新列表项添加到主列表时,我希望与主列表关联的事件处理程序相应地更新所有子站点。

例如,如果添加了项目,则将其添加到每个子站点的列表中

(如果更新了项目),

如果删除了项目,则更新每个子站点的相应列表项,从我尝试使用 SPListItem 尝试的每个子站点中删除相应的列表项

。 listItem 的 Copy 方法和 CopyTo 方法都无济于事。执行这种技术的最佳实践是什么?

I have a site which contains a custom list Master. I have a number of sub sites which contain copies of this list. When someone edits or adds a new list item to the master list, I would like all sub sites to be updated accordingly by an event handler which is associated with the master list.

e.g. if item is added, add it to the list of each sub site

if item is updated, update the appropriate list item of each sub site

if item is deleted, delete the appropriate list item from each sub site

I have tried using the SPListItem.Copy method and also the CopyTo method of the listItem to no avail. What is the best practice of doing this kind of technique?

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

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

发布评论

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

评论(2

她说她爱他 2024-09-04 08:04:55

我相信 SPListItem.Copy 和 SPListItem.CopyTo 仅当目标列表与原始项目位于同一 SPWeb 上时才有效。我假设这些列表项有一些“身份”字段,该字段不仅将其与其他列表项区分开来,而且在所有子网站和顶级网站中始终相同(与 ID 不同,ID 不是 100) % 在您的控制之下)。可以是标题,可以是以编程方式分配的编号,可以是任何东西。我将其称为“身份”字段。

我假设您了解事件处理程序。如果不这样做,您可以在此处查看一个非常基本的示例这解释了所有核心概念。

删除是最容易处理的事情。只需迭代子站点,迭代主列表以查找具有正确“身份”字段的项目,然后对其调用 SPListItem.Delete() 即可。这应该足以放入 ItemDeleting 事件。

添加稍微困难一些。再次遍历子站点,但这次使用如下方法。

SPListItem target = list.Items.Add();
target["Title"] = properties.AfterProperties["Title"];
//Repeat similar assignments for all fields in the list item which can be assigned during creation.
target.Update();

必须对其进行修改,以包含每个可以修改的字段,以及“身份”字段(如果您尚未包含它)。您不必担心自动分配的任何内容(如果 Copy/CopyTo 有效,SharePoint 无论如何都会处理它们)。将其放入 ItemAdded 事件中。

最后,更新项目与添加项目非常相似,只不过不是调用 list.Items.Add(),而是通过迭代主列表并获取具有正确“身份”字段的项目来获取正确的项目。将其放入 ItemUpdated 事件中。

您可能需要确保主列表的子网站上的权限与顶级网站上的权限相同。希望这对你有用!

I believe that SPListItem.Copy and SPListItem.CopyTo will only work if the target list is on the same SPWeb as the original item. I'm assuming that these list items have some "identity" field which not only distinguishes it from the other list items, but also is always the same across all of the subsites and the top level site (unlike ID, which isn't 100% under your control). Could be the title, could be a programmatically assigned number, could be anything. I'll just call this the "identity" field.

I am assuming you know Event Handlers. If you don't, you can see a very basic example here that explains all the core concepts.

Deleting is the easiest thing to handle. Just iterate through the subsites, iterate through the Master list for the item with the correct "identity" field, and call SPListItem.Delete() on it. That should be sufficient to put in an ItemDeleting event.

Adding is slightly more difficult. Once again iterate through the subsites, but this time use a method like follows.

SPListItem target = list.Items.Add();
target["Title"] = properties.AfterProperties["Title"];
//Repeat similar assignments for all fields in the list item which can be assigned during creation.
target.Update();

This will have to be modified to include every field which can be modified, as well as the "identity" field if you didn't already include it. You shouldn't have to worry about anything which would be automatically assigned (SharePoint would handle them anyway if Copy/CopyTo had worked). Put it in an ItemAdded event.

Finally, updating the item is very similar to adding an item, only instead of calling list.Items.Add(), you instead get the correct item by iterating through the Master list and getting the one with the correct "identity" field. Put it in an ItemUpdated event.

You might want to make sure that permissions on the subsites for the Master List are the same as on the top level site. Hope this works for you!

好倦 2024-09-04 08:04:55

如果它是您想要用作查找列的主列表,您可以在根站点中创建该列表,然后将站点列指向它。然后可以在您的任何子网站列表中使用该网站栏。

If it is a master list that you want to use as a lookup column, you can create the list in your root site and then point a site column to it. That site column can then be used in any of your subsite lists.

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