Logo 
Search:

Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Sharepoint Customer Timer Job

  Asked By: Erik    Date: Jan 18    Category: Sharepoint    Views: 5803

I followed Andrew's (Customer Timer JOb) article and modified the
code. and also install/acitvate feature without any problem, but it
is not appearing in TImer JOb Definitions list nor in Timer JOb
status, infact job is also not running. Here is my code, please
review and let me know whats wrong I am doing here

*--- Start Class1
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint.Utilities;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Net;
using System.Net.Mail;

namespace JobMail
{
public class EmailJob : SPJobDefinition
{




public EmailJob()
: base()
{
}
public EmailJob(string jobName, SPService service, SPServer
server, SPJobLockType targetType)
: base(jobName, service, server, targetType)
{
}
public EmailJob(string jobName, SPWebApplication
webApplication)
: base(jobName, webApplication, null,
SPJobLockType.ContentDatabase)
{
this.Title = "Email Job";
}
public override void Execute(Guid contentDbId)
{


SPWebApplication webApplication = this.Parent as
SPWebApplication;
SPContentDatabase contentDb =
webApplication.ContentDatabases[contentDbId];

SPSite site = new SPSite("http://moss");
SPWeb web = site.OpenWeb();
string Msg = "";
Msg = "test email";

SPUtility.SendEmail(web, false,
false, "ak@...", "Web Discussion Report", Msg);

}
}
}

*--- End Class1



*--- Start Class2

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint.Utilities;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Net;
using System.Net.Mail;

namespace JobMail
{
class TaskLoggerJobInstaller : SPFeatureReceiver {
const string TASK_LOGGER_JOB_NAME = "EmailLogger";
public override void FeatureInstalled
(SPFeatureReceiverProperties properties) {
}

public override void FeatureUninstalling
(SPFeatureReceiverProperties properties) {
}

public override void FeatureActivated
(SPFeatureReceiverProperties properties) {
SPSite site = properties.Feature.Parent as SPSite;

// make sure the job isn't already registered
foreach (SPJobDefinition job in
site.WebApplication.JobDefinitions) {
if (job.Name == TASK_LOGGER_JOB_NAME)
job.Delete();
}

// install the job
EmailJob taskLoggerJob = new EmailJob(TASK_LOGGER_JOB_NAME,
site.WebApplication);

SPMinuteSchedule schedule = new SPMinuteSchedule();
schedule.BeginSecond = 0;
schedule.EndSecond = 59;
schedule.Interval = 5;
taskLoggerJob.Schedule = schedule;

taskLoggerJob.Update();
}

public override void FeatureDeactivating
(SPFeatureReceiverProperties properties) {
SPSite site = properties.Feature.Parent as SPSite;

// delete the job
foreach (SPJobDefinition job in
site.WebApplication.JobDefinitions) {
if (job.Name == TASK_LOGGER_JOB_NAME)
job.Delete();
}
}
}
}

*--- End Class2

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on Sharepoint Customer Timer Job Or get search suggestion and latest updates.




Tagged: