此方法将任何列表项及其关联的文件和属性复制到同一网站集中的任何位置(可能还有其他Web应用程序,但我没有't tested). SharePoint automatically maintains the link to the source item as well if you view the item'属性或使用其下拉菜单 . 此链接可以通过UnlinkFromCopySource删除 .
CopyTo的唯一技巧是目标位置需要完整的URL .
public class EventReceiverTest : SPItemEventReceiver
{
public override void ItemAdded(SPItemEventProperties properties)
{
properties.ListItem.CopyTo(
properties.WebUrl + "/Destination/" + properties.ListItem.File.Name);
}
}
1 回答
使用项目事件接收器并覆盖ItemAdded事件 . SPItemEventProperties将通过ListItem属性为您提供对列表项的引用 .
有两种方法可以做到这一点(感谢您发现CopyTo) .
Method 1: Use CopyTo
此方法将任何列表项及其关联的文件和属性复制到同一网站集中的任何位置(可能还有其他Web应用程序,但我没有't tested). SharePoint automatically maintains the link to the source item as well if you view the item'属性或使用其下拉菜单 . 此链接可以通过UnlinkFromCopySource删除 .
CopyTo的唯一技巧是目标位置需要完整的URL .
Method 2: Stream copy, manually set properties
只有在需要更多控制复制哪些项属性或者需要更改文件内容时,才需要使用此方法 .
Deployment
您还有各种部署选项 . 您可以将事件接收器与连接到内容类型或列表的功能相关联,然后以编程方式添加它们 . 有关详细信息,请参阅this article at SharePointDevWiki .