一般情况下对IT管理者来说,在SharePointFarm中维护Feature,更喜欢使用命令行实现,这样可以省去登录到具体站点的操作。比如IT接到enduser的一个需求,要开启SiteCollectionFeature,如果直接操作......
2023-01-12
在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.Parent as SPSite;
// make sure the job isn't already registered
foreach (SPJobDefinition job in 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.Parent as SPSite;
// delete the job
foreach (SPJobDefinition job in site.WebApplication.JobDefinitions)
{
if (job.Name == JOB_NAME)
{
job.Delete();
}
}
}
6。部署之后,到管理中心,作业定义中,查看是否已经部署成功,如下图,我们看到,timerjobTest已经成功部署,如下图
7。需要重新启动服务,如下图
这时候我们的timer job 就创建完成了。
相关文章
一般情况下对IT管理者来说,在SharePointFarm中维护Feature,更喜欢使用命令行实现,这样可以省去登录到具体站点的操作。比如IT接到enduser的一个需求,要开启SiteCollectionFeature,如果直接操作......
2023-01-12
我们经常会在SharePoint网站集的权限列表中看到某个user有LimitedAccessPermission,但是我们都知道或者试过,在SharePointsitecollection中没有办法直接添加user赋予LimitedAccess权限,并且LimitedAccess这个......
2023-01-12
在这样的场景下,比如统计员工的个人信息,IT会在SharePoint中新建list,加一些需要填写的栏位,然后让公司员工登录填写。这时候比起大家都能看到彼此信息而言,从公司角度更想让员工只能......
2023-01-12
大多数企业使用SharePoint文档库时,都会建议EndUser在编辑文档前先做CheckOut动作,这样可以保证文档在当前用户编辑过程中,其他人只能view而不能edit,防止多人同时修改同一文件互相影响的......
2023-01-12
为了记录SharePointLibrary/List中file/Item的修改情况,ITAdministrator会在List/Library的VersionSettings中开启Version管控设置。之后用户每次编辑item/file保存就会生成一个新的version记录,这样我们就会知道......
2023-01-12