簡體   English   中英

創建一個計時器作業,每月運行一次,該作業將共享點列表項導出到excel並存儲在文檔庫中

[英]create a timer job to run once a month which exports sharepoint list items to excel and stores in a document library

我想創建一個計時器作業或工作流,該作業每月運行一次,並將共享點列表數據導出到excel,並將此文件存儲在文檔庫中。

我已經從下面的鏈接下載了用於創建計時器作業的代碼,但不知道如何包括上述要求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(); 

            } 

}  

我也建議您不要使用SharePoint計時器作業引擎。 絕對不穩定。 有時,作業根本不會trigger ,它們很難實例化且緩慢。

當然,您總是可以花時間調整SharePoint以實現穩定性,但是並不能保證。 我知道這聽起來很必要,但是請相信我,我不記得我們使用此引擎遇到的所有問題,但是我們為此花費了很多時間。

如前所述,我建議您使用Quartz.NETWindows Scheduler 這些是久經考驗的解決方案,也被許多人用於SharePoint。

我們在公司實施了Quartz.Net for SharePoint,我們所有的Timer Jobs都在此引擎上運行。 兩年來我們沒有小故障。

最好的祝福。

您應該將SPMinuteSchedule更改為SPMonthlyByDaySchedule,請參閱http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spschedule.aspx

但是,我的建議是使用Windows Server Scheduler和控制台應用程序。 易於更改,易於維護(不是iisreset !!),並且易於記錄所有內容。 我們將控制台應用程序用於各種計划的工作,時間從1小時到1天不等。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM