我尝试通过一些示例来了解如何创建共享点事件接收器。大多数示例的说明都相当简单。因此,我能够在 Visual Studio 2010 中创建一个共享点事件接收器项目(例如:添加项目或删除站点)并部署到服务器和站点。我检查了该功能并已激活。我进行了一些测试,例如删除测试站点甚至上传文件。但是我放入代码中的测试错误消息从未运行。我无法弄清楚为什么这些事件永远不会被触发。
以下是我的代码示例:
using System;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.Workflow;
namespace DeletingSite.EventReceiver1
{
/// <summary>
/// Web Events
/// </summary>
public class EventReceiver1 : SPWebEventReceiver
{
/// <summary>
/// A site is being deleted.
/// </summary>
public override void WebDeleting(SPWebEventProperties properties)
{
base.WebDeleting(properties);
properties.Cancel = true;
properties.ErrorMessage = "You cannot ";
}
}
}