sharepoint 2010 如何创建一个timer job
来源:互联网 发布:大唐网络 国企 编辑:程序博客网 时间:2024/05/22 14:45
在sharepoint的开发和应用中,经常会使用到,需要定时执行或者更新数据,我们可以用sharepoint自带的timer job来实现。
1。创建一个sharepoint 项目,名称为TimerJobTest;
2。创建一个class文件,名称为TimerJobClass;继承SPJobDefinition,如下图
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Administration;
namespace TimerJobTest
{
public class TimerJobClass : SPJobDefinition
{
public TimerJobClass(): base(){}
public TimerJobClass(string jobName,SPService service, SPServer server,
SPJobLockType targetType)
: base(jobName, service, server, targetType)
{
}
public TimerJobClass(string jobName,SPWebApplication webApplication)
: base(jobName, webApplication,null, SPJobLockType.ContentDatabase)
{
this.Title = jobName;
}
public override void Execute(Guid contentDbId)
{
//这里就是我们要执行的函数方法
}
}
}
3。添加一个feature,名称为TimerJob,并且选择范围为site,如下图:
4。添加一个事件接收器,如下图:
5。需要override其中的两个函数,
override void FeatureActivated(SPFeatureReceiverProperties properties),部署timer job函数
override void FeatureDeactivating(SPFeatureReceiverProperties properties) 删除timer job函数
方法如下:
const string JOB_NAME ="TimerJobTest";
// Uncomment the method below to handle the event raised after a feature has been activated.
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPSite site = properties.Feature.Parentas SPSite;
// make sure the job isn't already registered
foreach (SPJobDefinition jobin site.WebApplication.JobDefinitions)
{
if (job.Name == JOB_NAME)
{
job.Delete();
}
}
// install the job
TimerJobClass Doc = new TimerJobClass(JOB_NAME, site.WebApplication);
SPMinuteSchedule schedule =new SPMinuteSchedule();
schedule.BeginSecond = 0;
schedule.EndSecond = 59;
schedule.Interval = 1;
Doc.Schedule = schedule;
Doc.Update();
}
public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
SPSite site = properties.Feature.Parentas SPSite;
// delete the job
foreach (SPJobDefinition jobin site.WebApplication.JobDefinitions)
{
if (job.Name == JOB_NAME)
{
job.Delete();
}
}
}
6。部署之后,到管理中心,作业定义中,查看是否已经部署成功,如下图,我们看到,timerjobTest已经成功部署,如下图
7。需要重新启动服务,如下图
这时候我们的timer job 就创建完成了。
附件下载地址:http://download.csdn.net/download/cxx2325938/4889649。
广州京微信息科技有限公司,.微软sharepoint解决方案提供商。
- sharepoint 2010 如何创建一个timer job
- 创建SharePoint 2010 Timer Job
- SharePoint 2010 自定义计时器(Timer Job)
- Sharepoint Custom Timer Job
- 清除sharepoint timer job 缓存
- sharepoint 2010 用timer job 实现文档下载次数
- sharepoint 2010 用timer job 实现列表评论次数
- sharepoint timer job 读取config文件内容
- SharePoint 2013 中开发Timer Job
- SharePoint中开发自定义Timer Job
- 在sharepoint 2010上如何创建一个调查
- SharePoint Debug - SharePoint timer job 发送重复邮件
- sharepoint 2013 如何创建一个webservice获取sharepoint列表数据
- SharePoint 2010 Timer Job. 激活发生错误 The EXECUTE permission was denied on the object 'proc_putObject'
- SharePoint 2010 自定义Timer job 问题总结(拒绝访问,Execute方法不执行,不及时更新)
- SharePoint timer job运行时的账户问题
- orace 创建一个job
- 创建一个 Timer
- Oracle 11g R2的卸载与重装
- Linux下启动java程序的通用脚本sh
- hdu1015
- javascript history对象
- linux 中的rz 和sz的安装和使用
- sharepoint 2010 如何创建一个timer job
- javascript location对象
- 我的家人
- Java多线程(十)之ReentrantReadWriteLock深入分析
- 少编码多思考:代码越多 问题越多
- 转发乱序与TCP
- 联赛
- Windows Phone 8开发之Hyper-V支持的另一种环境
- 高效敏捷的十大经验法则