通过Feature部署Sharepoint 2013的EventReceiver

Sharepoint 2013中对EventHandler的部署有不少改进。记录一下初步感受。

1. 生产Feature文件

在SP2013中对列表或文档库的部署可以不再用程序。可以通过按web等方式部署,在激活Feature的方式。在每个web下都有相应的feature来控制。方便许多。

首先如下图,在项目的Feature属性中,选择WSP的部署范围:


这样生成的WSP包中的Manifest.xml会设置相应的Scope,具体细节的动老外已经描述好了,就不翻译了:

Event receivers are usually deployed via a feature. A feature can be scoped to farm, web application, Site collection or web.
 The scope of a feature has nothing to do with the way SharePoint deploys a solution that installs that feature.
 A solution is deployed either globally or to a web application. SharePoint decides how to deploy a solution according to the solution manifest :
 - If in the solution manifest, the assembly's attribute DeployementTarget="GlobalAssemblyCache", SharePoint will not ask you for the web application.
 - If the attribute DeployementTarget="WebApplication", SharePoint will ask you for the web application to which the solution will be deployed.
 - If the attribute DeployementTarget="GlobalAssemblyCache" and SafeControls are needed for the assembly, especially for web parts, SharePoint will ask for the we application, because the safe controls are added to the web.config of the web application.
 To see the solution manifest, change the extension of your solution file from .wsp to .cab e.g. Mysolution.wsp to Mysolution.cab. Then use windows explorer to open the file and extract the file Manifest.xml. 

2. 编辑Elements.xml

如上一步选择的是web,现在就需要在Elements.xml指定部署到哪些文档库中。

如下图,打开“Elements.xml”,Feature文件可以通过Receivers中的“ListTemplateId”或“ListUrl”指定部署在哪些文档库或列表中,上传一个写好的“Elements.xml”:

第一个“Receive”段是部署给所有的文档库

第二个“Receive”段是部署给Static Name(同URL)为“Doclib”的文档库,



3.生产WSP文件

Feature和Element都写好后,右键点击solution选择发布,自动生成WSP,太TM方便了,原来在VS2008做一个WSP麻烦死。


4. 部署WSP

打开SP的cmd部署WSP文件,用:Add-SPSolution和Install-SPSolution。具体参数加 -?

如:

Add-SPSolution path\eventreceive.wsp 就可以。不再用stsadm,参数也简单。


5. 最后一步激活web的Feature。

打开portal - 网站设置 - 管理网站功能。找到刚刚部署的WSP文件,点击激活。Over


备注一下常用的ListTemplateId

其中ListTemplateId(Elements.xml文件中属性) 主要类型如下,根据类型输入相应的ID激活Feature:

100泛型列表 
101  文档库
102 调查
103链接列表 
104通知列表 
105 联系人列表 
106事件列表
107任务列表 
108讨论板
109图片库 
110 数据源 
111 网站模板库
112用户信息列表
113Web 部件库 
114列表模板库 
115XML 表单库
116母版页样式库
117无代码工作流
118自定义工作流程 
119Wiki 网页库
120自定义列表网格
130数据连接库
140工作流历史记录 
150甘特图任务列表
200会议序列列表
201会议议程列表
202会议与会者列表 
204会议决策列表
207会议目标列表
210会议文本框
211会议讨论事项列表 
212会议工作区网页列表
301博客文章列表
302博客评论列表
303博客类别列表 
1100问题跟踪
1200管理员任务列表

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值