zevenseas


 

Using the SchedulePicker

There isn’t much to find about the SchedulePicker Class (in the Microsoft.SharePoint.WebControls namespace) which is very handy when it comes to creating a SPSchedule. The question if of course, when do you need to have a SPSchedule? Well it could be very handy for instance when creating application pages that handle the scheduling of custom timer jobs. So instead of creating your own dropdown’s with all the days of the week and all the possible times and converting to those the proper schedule types that SharePoint has (SPMinuteSchedule, SPHourlySchedule, etc) you can use a control that does everything for you. The only thing you need to specify what the options are that an user can select from by setting the properties.

So using this line in my application page:

<%@ Register TagPrefix="wssuc" TagName="SchedulePicker" src="~/_controltemplates/SchedulePicker.ascx" %>
<
wssuc:SchedulePicker id="SchedulerAction" Weekly="True" Monthly="True" Enabled="True" EnableStateView="True" runat="server"/>

Generates this result:

 

Pretty cool eh? So if you only want to have the options to schedule during the week you remove the “Monthly=’True’” property and that part of the control will not be visible.

The only code you have to write to schedule your timer job based on what you configure in this control is this:

//reference the control like this
protected SchedulePicker Scheduler

private void InstallTimerJob()
{
CustomTimerJob customTimerJob = new CustomTimerJob("MyCustomJob", webApplication);               
customTimerJob.Schedule = Scheduler.Schedule;                
customTimerJob.Update();
}

And the code to set the control with the configured values is like this:

protected override void OnLoadComplete(EventArgs e)
{
    SPWebApplication webApplication = webApplicationSelector.CurrentItem;
    if (!Page.IsPostBack)
    {            
        foreach (SPJobDefinition job in webApplication.JobDefinitions)
        {
            if (job.Name == "MyCustomJob" )
            {                       
                Scheduler.ScheduleString = job.Schedule.ToString();
            }
            
        }       
        
    }
}

I really love the reusing of SharePoint controls like this! Saves you a lot of effort and time ;)

Technorati Tags: ,

Links to this post

Comments

On 26 May 2009 09:07, Karine

I hate it when people copy/paste interesting blog posts. Fortunately this one mentions that you are the original poster:
http://blogs.msdn.com/varun_malhotra/archive/2009/05/26/reusing-spschedulepicker-control.aspx
Keep up the good work!
Karine

On 26 May 2009 10:54, Robin

Hi Karine,

thanks! And FYI, the poster did not include the link this morning. I mailed him and now there is link in his post.. still obscurely at the bottom. But it's better then nothing eh? ;)

You what is really funny.. everytime I wanted to blog about a SharePoint webcontrol I 'found', you almost everytime have a post about it. So keep up the good work over there in Belgium as well! ;)

Name

Url

Email

Comments

CAPTCHA Image Validation



 
 
 

© 2009 Community Kit For SharePoint