Geeks With Blogs
Molnar Tibor blog

When a new timer job is created for Sharepoint, it has to be programatically installed in a SPWebApplication.JobDefinitions of type SPJobDefinitionCollection. If the timer job have to receive some settings during run time, one option would be to use the .Net application configuration feature.

First you might think to copy the configuration section from the app.config of the dll where the timer job resides into the web.config of the web application where the timer job is registered. The first catch: the timer job is loaded by the timer service, which is the 'Windows SharePoint Services Timer' Windows service on the web front end servers and runs the "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\BIN\OWSTIMER.EXE" executable, so we have to configure this service.

This can be done by creating the OWSTIMER.EXE.config file near the exe file, and put there the timer job configuration section.

Don't forget to restart the timer service :-).

Posted on Wednesday, July 30, 2008 2:19 AM SharePoint 2007 | Back to top


Comments on this post: Application setting for Sharepoint timer jobs

# re: Application setting for Sharepoint timer jobs
Requesting Gravatar...
can you please provide me the sample code for OWSTIMER.EXE.config as i want to set the config parameters like SiteUrl, SMTPHost,and other etc..

can you also brief me about how to deploy the timer job on client server using WSP (package).

Thanks in advance.
Left by pragna on Sep 01, 2008 11:11 PM

# re
Requesting Gravatar...
Yes, no problem. The OWSTIMER.EXE.config file is a normal .Net binary config file and contains the configuration sections for your dll, basically you copy the configuration section from the app.config file generated by Visual Studio for your dll into this file. Fo example:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="youAssemblyNamespace.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<applicationSettings>
<youAssemblyNamespace.Properties.Settings>
<setting name="SiteUrl" serializeAs="String">
<value>setting1value</value>
</setting>
<setting name="SMTPHost" serializeAs="String">
<value>settingValue</value>
</setting>
</youAssemblyNamespace.Properties.Settings>
</applicationSettings>
</configuration>

The deployment of the timer job is done in a feature receiver, code sample:

// Make sure the job isn't already registered.
foreach (SPJobDefinition job in webApplication.JobDefinitions) {
if (job.Name == Globals.TaskOverdueNotificatorJobName)
job.Delete();
}

// Install the job.
YourCustomJobClass yourCustomJob = new YourCustomJobClass (webApplication);

SPSchedule schedule = null;


SPDailySchedule dailySchedule = new SPDailySchedule();
dailySchedule.BeginHour = 0;
dailySchedule.BeginMinute = 0;
dailySchedule.BeginSecond = 0;
dailySchedule.EndHour = 1;
dailySchedule.EndMinute = 0;
dailySchedule.EndSecond = 0;
schedule = dailySchedule;

yourCustomJob.Schedule = schedule;
yourCustomJob.Update();
Left by Tibor Molnar on Sep 01, 2008 11:39 PM

# re: Application setting for Sharepoint timer jobs
Requesting Gravatar...
I need to run an exe file using sharepoint custome timer jobs.
can you briefly explain me how can i do this.i knew that i have to use spjobdefination class,spscheduler class and spminitescheduler classes.i don't know proper way to do this.
Thanks in advance.
Left by Arjun on Mar 09, 2009 7:16 PM

# re: Application setting for Sharepoint timer jobs
Requesting Gravatar...
Hi,
thanks a lot..........

Left by Vikram kumar reddy on Aug 13, 2010 6:37 AM

Your comment:
 (will show your gravatar)


Copyright © Molnar Tibor | Powered by: GeeksWithBlogs.net