C# 创建每月运行一次的计时器作业,将sharepoint列表项导出到excel并存储在文档库中
我想创建一个计时器作业或工作流,每月运行一次,将sharepoint列表数据导出到excel,并将此文件存储在文档库中 我已经从下面的链接下载了创建计时器作业的代码,但不知道如何包含上述要求C# 创建每月运行一次的计时器作业,将sharepoint列表项导出到excel并存储在文档库中,c#,excel,sharepoint,timer,sharepoint-2010,C#,Excel,Sharepoint,Timer,Sharepoint 2010,我想创建一个计时器作业或工作流,每月运行一次,将sharepoint列表数据导出到excel,并将此文件存储在文档库中 我已经从下面的链接下载了创建计时器作业的代码,但不知道如何包含上述要求 您应该将SPMinuteSchedule更改为SPMonthlyByDaySchedule,请参阅 但是,我的建议是使用windows服务器调度器和控制台应用程序。易于更改、易于维护(不是iisreset!!),并且易于记录所有内容。我们将控制台应用程序用于各种计划作业,从1小时到1天不等。我还建议您不要
您应该将SPMinuteSchedule更改为SPMonthlyByDaySchedule,请参阅
但是,我的建议是使用windows服务器调度器和控制台应用程序。易于更改、易于维护(不是iisreset!!),并且易于记录所有内容。我们将控制台应用程序用于各种计划作业,从1小时到1天不等。我还建议您不要使用
SharePoint
计时器作业引擎。
绝对不稳定。
有时作业根本不触发,它们很难实例化,也很慢
当然,您可以随时花时间调整SharePoint以实现稳定性,但这并不能保证。我知道这听起来很有必要,但相信我,我不记得我们在这台发动机上遇到的所有问题,但我们在这方面浪费了很多时间
如前所述,我建议您使用Quartz.NET或Windows调度程序。
这些都是经过充分验证的解决方案,被许多人使用,也用于SharePoint
我们在我的公司实现了Quartz.Net for SharePoint,我们所有的计时器作业都在这个引擎上运行。
两年来我们没有任何问题
问候。请您澄清“如何包括上述要求”?现在你的帖子只包含需求,没有问题需要解决。旁注:请确保在您的帖子中只包含与您的问题直接相关的最低数量的代码。您能给我有关sharepoint console application scheduler中任何示例的链接吗?关于如何为console application+scom创建schedculer的链接
//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();
}
}