一步一步SharePoint 2007之三十三:实现通用Event Handler(1)——完成准备工作
为了更清晰地让朋友们了解实现通用Event Handler的几个步骤,本篇文章将被分割成两个小的部分,第一部分讲解完成准备工作,第二部分讲解尝试Event Handler。因此而给大家带来的阅读不便,就请海涵了:)下面将记录每一步的操作过程。
1、首先打开打开Microsoft Visual Studio 2005,创建一个名为Eallies.EventHandler.SP2007的Class Library。
http://blog.运维网.com/attachment/200805/200805261211784357171.jpg
2、创建完成后,将默认的Class1.cs改名为ListHandler.cs。
http://blog.运维网.com/attachment/200805/200805261211784374484.jpg
3、为项目添加Microsoft.SharePoint.dll的引用。
4、将项目的输出目录更改为C:\Inetpub\wwwroot\wss\VirtualDirectories\9001\_app_bin。
5、为项目创建强名称。
6、更改ListHandler.cs为如下的代码:
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4
5 using Microsoft.SharePoint;
6
7 namespace Eallies.EventHandler.SP2007
8 {
9 public class ListHandler : SPItemEventReceiver
10 {
11 public override void ItemDeleting(SPItemEventProperties properties)
12 {
13 properties.Cancel = true;
14 properties.ErrorMessage = "You have no access to delete it.";
15 }
16 }
17 }
http://blog.运维网.com/attachment/200805/200805261211784392734.jpg
7、向解决方案中添加一个名为Eallies.EventHandler.Register的Console Application项目。
8、为Eallies.EventHandler.Register项目添加Microsoft.SharePoint.dll的引用。
9、使用Reflector找到Eallies.EventHandler.SP2007项目的Assembly信息。
http://blog.运维网.com/attachment/200805/200805261211784409328.jpg
10、将Eallies.EventHandler.Register项目中的Program.cs更改为如下的代码:
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4
5 using Microsoft.SharePoint;
6
7 namespace Eallies.EventHandler.Register
8 {
9 class Program
10 {
11 static void Main(string[] args)
12 {
13 SPSite site = new SPSite("http://denny-zhang:9001/sites/Wodeweb");
14 SPWeb web = site.OpenWeb("Docs");
15 SPList list = web.Lists["Announcements"];
16
17 list.EventReceivers.Add(SPEventReceiverType.ItemDeleting, "Eallies.EventHandler.SP2007, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c7f921ec4a7dede8", "Eallies.EventHandler.SP2007.ListHandler");
18 }
19 }
20 }
http://blog.运维网.com/attachment/200805/200805261211784422453.jpg
11、编译Eallies.EventHandler.SP2007项目,并将编译后的DLL加入到操作系统的GAC中。
http://blog.运维网.com/attachment/200805/200805261211784441125.jpg
12、运行Eallies.EventHandler.Register项目。
至此,实现通用Event Handler的准备工作就完成了。
下一篇文章我将记录如何实现通用Event Handler的最后一部分——尝试Event Handler的过程。欢迎大家继续关注:)多谢!
附件:http://down.运维网.com/data/2349988
页:
[1]