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:
Can I have multiple SPSchedule in my page?
Post a Comment