I am facing an issue while trying to write the custom Timer Job in SharePoint 2007.
Have overridden the Execute method
public override void Execute(Guid contentDbId)
{
using (SPSite oSPsite = new SPSite("http://esssharepoint20"))
{
oSPsite.AllowUnsafeUpdates = true;
using (SPWeb oSPWeb = oSPsite.OpenWeb())
{
SPList splist = oSPWeb.Lists["PhoneBook"];
SPListItem spItem = splist.Items.Add();
spItem["PhoneNumber"] = DateTime.Now.ToString();
spItem.SystemUpdate();
}
oSPsite.AllowUnsafeUpdates = false;
}
}
and registering the Job using a Feature
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
//string oSPsiteURL = (properties.Feature.Parent as SPSite).Url;
using (SPSite phoneBookSite = properties.Feature.Parent as SPSite)
{
SPWebApplication phoneBookApplication = phoneBookSite.WebApplication;
SPJobDefinitionCollection timerJobCollection = phoneBookApplication.JobDefinitions;
SPDailySchedule jobSchedule = new SPDailySchedule();
jobSchedule.BeginHour = 0;
jobSchedule.BeginMinute = 0;
jobSchedule.BeginSecond = 0;
jobSchedule.EndHour = 2;
jobSchedule.EndMinute = 30;
jobSchedule.EndSecond = 0;
phoneBookPurgeData phoneBookTimerObj = new phoneBookPurgeData(
"PhoneBook Timer Job",
phoneBookApplication
);
phoneBookTimerObj.Schedule = jobSchedule;
timerJobCollection.Add(phoneBookTimerObj);
phoneBookApplication.Update();
}
//throw new Exception("The method or operation is not implemented.");
}
however it throws the below error:
08/09/2011 22:29:30.60 Timer 7psa Critical The Execute method of job definition PhoneBookTimerJob.phoneBookPurgeData (ID 2519a803-af39-4a2a-ae42-8d177a609ed8) threw an exception. More information is included below. Value cannot be null. Parameter name: uriString
08/09/2011 22:29:30.60 OWSTIMER.EXE (0x097C) 0x0C7C Windows SharePoint Services Timer 72ae Unexpected Exception stack trace: at System.Uri..ctor(String uriString) at Microsoft.SharePoint.SPSite..ctor(String requestUrl) at PhoneBookTimerJob.phoneBookPurgeData.Execute(Guid contentDbId) at Microsoft.SharePoint.Administration.SPTimerJobInvoke.Invoke(TimerJobExecuteData& data, Int32& result)
Webapplication is still exists, what am I doing wrong? and how to fix this?