Tuesday, July 14, 2009

Understanding SchedulePicker class and using it as control

Hi All,

Today I am going to discuss about SchedulePicker and how to use it as control in webpart. In my earlier post, I mentioned about creating the custom timer job. This is one step which is similar to that post. This class can be used to allow the user to ask to created job schedule by giving timings and schedule duration by them.

For example, you have created one class which inherits from SPJobDefinition and hence actually implements the execute method for scheduling purpose. So here what we can do is we can give an option to use to select the times and all. After use selects the time and schedule we can assign the selected schedule to the custom job definition.

This is in Microsoft.Sharepoint.WebControls namespace. You can find it under 12 hives control templates. Name of the control is SchedulePicker.ascx.

So you need to register the namespace and then you can use this control in your web part or in any other way you want.

<%@ Register TagPrefix="wssuc" TagName="SchedulePicker" src="~/_controltemplates/SchedulePicker.ascx" %>


And then using the control like this:

<wssuc:SchedulePicker id="myScheduler" Weekly="True" Monthly="True" Enabled="True" EnableStateView="True" runat="server"/>


The above setting will allow you to select between the monthly schedule or weekly scheduling. Other options are also available like Daily, Hourly.

Then declare the control like

private Control ctrlUserControl;

Protected SchedulePicker myScheduler;

string strUserControlPath = "/_controltemplates/{your ascx file}";

this.ctrlUserControl = this.Page.LoadControl(strUserControlPath);

myScheduler = this.ctrlUserControl.FindControl(“myScheduler”) as SchedulePicker;


Finally, Initialize the class which is your definition class and then set the Schedule property with the myScheduler.Schedule.

i.e
{Customjobdefinitionclass}.Schedule = myScheduler.Schedule;


In this way, you have actually made the scheduling timing setting dynamic.

That’s it. Your job is done.

1 comment:

Anonymous said...

Can I have multiple SPSchedule in my page?




Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to sharepointkings@gmail.com with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!

If anyone would like to have their advertisement posted on this blog, please send us the requirement details to sharepointkings@gmail.com