创build一个计时器作业,每月运行一次,导出sharepoint列表项目并出现在文档库中

我想创build一个计时器作业或工作stream程,每月运行一次,并导出sharepoint列表数据,并将其存储在文档库中。

我已经下载的代码来创build计时器作业从下面的链接,但不知道如何包括上述要求http://code.msdn.microsoft.com/SharePoint-2010-Custom-416cd3a1

//Create class derived from SPJonDefinition Class class ListTimerJob : SPJobDefinition { public ListTimerJob() : base() { } public ListTimerJob(string jobName, SPService service, SPServer server, SPJobLockType targetType) : base(jobName, service, server, targetType) { } public ListTimerJob(string jobName, SPWebApplication webApplication) : base(jobName, webApplication, null, SPJobLockType.ContentDatabase) { this.Title = "List Timer Job"; } public override void Execute(Guid contentDbId) { // get a reference to the current site collection's content database SPWebApplication webApplication = this.Parent as SPWebApplication; SPContentDatabase contentDb = webApplication.ContentDatabases[contentDbId]; // get a reference to the "ListTimerJob" list in the RootWeb of the first site collection in the content database SPList Listjob = contentDb.Sites[0].RootWeb.Lists["ListTimerJob"]; // create a new list Item, set the Title to the current day/time, and update the item SPListItem newList = Listjob.Items.Add(); newList["Title"] = DateTime.Now.ToString(); newList.Update(); } } //Add Event receiver at Feature Level [Guid("9a724fdb-e423-4232-9626-0cffc53fb74b")] public class Feature1EventReceiver : SPFeatureReceiver { const string List_JOB_NAME = "ListLogger"; // 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 == List_JOB_NAME) job.Delete(); } // install the job ListTimerJob listLoggerJob = new ListTimerJob(List_JOB_NAME, site.WebApplication); SPMinuteSchedule schedule = new SPMinuteSchedule(); schedule.BeginSecond = 0; schedule.EndSecond = 59; schedule.Interval = 5; listLoggerJob.Schedule = schedule; listLoggerJob.Update(); } // Uncomment the method below to handle the event raised before a feature is deactivated. 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 == List_JOB_NAME) job.Delete(); } } 

您应该将SPMinuteSchedule更改为SPMonthlyByDaySchedule,请参阅http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spschedule.aspx

但是,我的build议是使用Windows服务器调度程序和控制台应用程序。 易于更改,易于维护(不是iisreset !!),并且易于logging所有内容。 我们使用控制台应用程序进行各种计划任务,从1小时到1天不等。

我也build议你不要使用SharePoint计时器作业引擎。 这绝对不稳定。 有时工作根本不会trigger ,他们很难实例化。

当然,你总是可以花时间调整SharePoint来实现稳定性,但是没有保证。 我知道这听起来是必要的,但相信我,我不记得我们用这个引擎的所有问题,但我们失去了很多时间。

如前所述,我build议你使用Quartz.NETWindows Scheduler 。 这些都是很好的解决scheme,许多人也使用SharePoint。

我们在我的公司实施了Quartz.Net for SharePoint,我们所有的计时器作业都在这个引擎上运行。 我们没有两年的小故障。

最好的祝福。