MOSS SDK学习(5)

MOSS SDK学习(5)

WSS2.0相比,我觉得WSS3.0在事件方面有两个最主要的改进:

1、  WSS2.0中的事件只能在事件已经发生过触发,而WSS3.0可以在事件发生前触发,比如在用户删除一个文件时触发来阻止用户删除文件

2、  WSS2.0中的事件只能附加在文档库中,而WSS3.0的事件可以附加在网站、列表(包括文档库)、文件上

 

这个例子主要演示的是WSS中最简单的事件操作和部署。

 

首先我们编写一个最简单的事件处理程序:

代码如下:

 

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;

namespace SimpleEventHandler
{
    
public class SimpleEventHandler : SPItemEventReceiver
    
{
        
public override void ItemUpdating(SPItemEventProperties properties)
        
{
            properties.Cancel 
= true;
            properties.ErrorMessage 
= "Updating is not supported.";
        }


        
public override void ItemAdded(SPItemEventProperties properties)
        
{
            properties.AfterProperties[
"Body"= "Body text maintained by the system.";
        }

    }

}

事件处理程序写好之后要把它部署到MOSS中去,有三种部署方式:

1、  通过SPWeb SPList的属性EventReceiversAdd方法

2、  声明列表类型,使用Feature.xml,注册成一个Feature,可以在网站内多处使用

3、  声明内容类型,可以做为内容类型的一部分来使用

 

这里我使用Feature的方式来部署,步骤如下:

1、  C:/Program Files/Common Files/Microsoft Shared/web server extensions/12/TEMPLATE/FEATURES 下建一个目录EventFeature

2、  在这个目录下新建一个文件 Feature.xml

<Feature Scope="Web"

  Title="测试事件"

  Id="C6458ADE-F5BB-498d-BB64-2E4FB19E08FB"

  xmlns="http://schemas.microsoft.com/sharepoint/">

  <ElementManifests>

    <ElementManifest Location="elements.xml"/>

  </ElementManifests>

</Feature>

         其中的id值可以使用VS2005工具的创建GUID生成

3、  在这个目录下新建一个文件elements.xml

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

  <Receivers ListTemplateId="104">

    <Receiver>

      <Name>SimpleEvent</Name>

      <Type>ItemUpdating</Type>

      <SequenceNumber>10000</SequenceNumber>

      <Assembly>SimpleEventHandler, Version=1.0.0.0,

        Culture=neutral, PublicKeyToken=99352c476b7ca41e</Assembly>

      <Class>SimpleEventHandler.SimpleEventHandler</Class>

      <Data></Data>

      <Filter></Filter>

    </Receiver>

  </Receivers>

</Elements>

其中的PublicKeyToken应该和dll中的一致,使用sn –T SimpleEventHandler.dll 命令取得,

ListTemplateId="104" 代表的是通知列表

摘抄WSS3.0 SDK中的不同列表类型的对应值:

Value

Description

100

Generic list

101

Document library

102

Survey

103

Links list

104

Announcements list

105

Contacts list

106

Events list

107

Tasks list

108

Discussion board

109

Picture library

110

Data sources

111

Site template gallery

113

Web Part gallery

114

List template gallery

115

XML Form library

117

No-code workflow library

118

Workflow process list

119

Web page library

120

Custom grid for a list

130

Data connection library

140

Workflow history list

150

Gantt tasks list

200

Meeting Series list

201

Meeting Agenda list

202

Meeting Attendees list

204

Meeting Decisions list

207

Meeting Objectives list

210

Meeting text box

211

Meeting Things To Bring list

212

Meeting Workspace Pages list

300

Portal Sites list.

1100

Issue tracking

2002

Personal document library

2003

Private document library

 

4、  dll文件部署到GAC

Gacutil –I SimpleEventHandler.dll

5、  Feature发布到网站

stsadm -o installfeature -filename EventFeature\feature.xml

 

stsadm -o activatefeature -filename EventFeature\feature.xml -url http://localhost:999/Docs

 

iisreset

部署好之后会作为网站功能显示在网站功能一览中

 

之后我们在文档中心的通知列表中加入一个通知,之后当更新时会抱错:

 

 

部署好之后就可以在MOSS中使用了,使用方法如下:

1、在MOSS的管理中下的Web 应用程序常规设置 设置 向后兼容的事件处理程序为启用

2、在文档列表的设置 〉高级设置中 填写 向后兼容的事件处理程序

  这两步在我们这个例子中用不到,这两步是以前WSS2.0的事件处理程序的使用方式。

 

下一个例子我准备再写一个稍微复杂一点的事件程序,然后使用第一种方式部署。

posted @ 2007-03-23 15:18  永春  阅读(2864)  评论(9编辑  收藏  举报