1

I have created a Timer Job and deployed the wsp to the central admin. The feature is installed and activated fine. I don't get any error. But i can't see the timer job in the Timer job list in central admin. I dont see the feature in the site collection feature either.
I followed Andrew Connel link and tried to install his sample into the central admin

http://www.andrewconnell.com/Creating-Custom-SharePoint-Timer-Jobs.

I don't see that timer job either . I have restarted the Timer services on SharePoint 2007 server.

  • How do you activate the feature for the package after you deploy the package to your web application? Do you activate it via the Site Collection Features page, or through stsadm? – Jeff Freeman Jul 15 '13 at 20:33
1

Since all SharePoint timer jobs are inheriting Microsoft.SharePoint.Administration.SPJobDefinition which inherits SPPersistedObject, these timer jobs are written in the Hierarchical Object Store which is directly in the SPFarm database. Here is some more information about the previous sentence.

Anyway, the point is that your context is important when activating features which install timer jobs because they have to install the timer jobs outside of your web application. So, if you were activating them in the SharePoint interface through the Site Collection Features page, please try to activate it instead with stsadm while logged in as a user with Farm Admin privileges in a command prompt run as Administrator.

Since you seem to like Andrew Connell links, here is one explaining in more detail what I wrote in the second paragraph. Hope this helps!

  • Thank you Jeff I did install and activate the features using STSADM commands. 2) The Timer job does not appear under Job Definitions in sharepoint manager. The feature however does appear under the Feature definitions in sharepoint manager – Jayant Rao Jul 17 '13 at 9:35
0

Thankyou Jeff for the Info.

1) I did install and activate the features using STSADM commands. 2) The Timer job does not appear under Job Definitions in sharepoint manager. The feature however does appear under the Feature definitions in sharepoint manager.

Please find my code below.

using System; using System.Collections.Generic; using System.Text; using Microsoft.SharePoint; using Microsoft.SharePoint.Administration; using System.Data; using System.Data.SqlClient; namespace Reminder.FeatureCode { public class Test:SPJobDefinition { private string _formStatus = string.Empty; public Test():base() {

    }
    public Test(string jobName, SPService service, SPServer server, SPJobLockType targetType): base(jobName, service, server, targetType)
    {
        this.Title = "Timer Job";
    }
    public Test(string jobName, SPWebApplication webApplication)
        : base(jobName, webApplication, null, SPJobLockType.ContentDatabase)
    {

        this.Title = "Timer Job";

    }

     private void SendEmail(string EmailBody, string Subject, string ToEmailAddress)
     {
         try
         {
             System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();

             msg.To.Add(ToEmailAddress);
             msg.From = new System.Net.Mail.MailAddress("****");
             msg.Subject = Subject;

             msg.IsBodyHtml = true;
             //EmailBody = " <b>Welcome to Send an Email!!</b><p> Example.<BR>";
             msg.Body = EmailBody;
             string smtp = "*****";
             System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(smtp);
             System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
             NetworkCred.UserName = "**";
             NetworkCred.Password = "**";
             NetworkCred.Domain = "**";
             client.Credentials = NetworkCred;
             client.Send(msg);
         }
         catch (Exception ex)
         {

             LogError(ex.InnerException.ToString(), ex.StackTrace);
         }

     }



    public override void Execute(Guid contentDbId)
     {
         System.Diagnostics.Debug.Assert(false);
         System.Diagnostics.Debug.WriteLine(SPContext.Current.Site.WebApplication.Name);
         StringBuilder _emailBody = new StringBuilder();
         string _staffName=string.Empty;
         string _Emailtext=string.Empty;
         string _url =string.Empty;
         string _formNo = string.Empty;
         string _staffEmailAddress = string.Empty;
         try
         {
             string url = @"http://url";
             using (SPSite site = new SPSite(url))
             {
                 using (SPWeb web = site.OpenWeb())
                 {
                     SPListItemCollection coll = web.Lists["test"].Items;
                     foreach (SPListItem item in coll)
                     {

                         if (!string.IsNullOrEmpty(_formStatus))
                         {
                             if (_formStatus == "Submitted")
                             {

                _emailBody.Append("<b>Welcome to Send an Email!!</b><p> Example.<BR>");   
                                 SendEmail(_emailBody.ToString(), _formStatus,_staffEmailAddress);

                             }

                         }

                     }
                 }
             }
         }
         catch (Exception ex)
         {

             LogError(ex.Source, ex.StackTrace + ex.InnerException.ToString());
         }


        //TODO: write here the code of your job!

    }

}
  public  class TimerJob : SPFeatureReceiver
{
    const string TASK_LOGGER_JOB_NAME = "Timer Job";
    public override void FeatureActivated(SPFeatureReceiverProperties properties)
    {
        //SPDiagnosticsService diag = new SPDiagnosticsService();


        try
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                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
                Reminder.FeatureCode.Test taskLoggerJob = new Reminder.FeatureCode.Test(TASK_LOGGER_JOB_NAME, site.WebApplication);

                SPMinuteSchedule schedule = new SPMinuteSchedule();
                schedule.BeginSecond = 0;
                schedule.EndSecond = 59;
                schedule.Interval = 2;

                //SPSchedule customSchedule = SPSchedule.FromString("daily at 01:45");

                taskLoggerJob.Schedule = schedule;

                taskLoggerJob.Update();
            });
        }
        catch (Exception ex)
        {

            LogError(ex.InnerException.ToString(), ex.StackTrace);

        }
    }

    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();
        }
    }

    public override void FeatureInstalled(SPFeatureReceiverProperties properties)
    {

    }

    public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
    {

    }

}

}

Feature <?xml version="1.0" encoding="utf-8"?> <Feature Id="f9101141-7463-49e3-911a-9e3a3b7f642f" Title="Timer Job" Description="Timer Job" Version="1.0.0.0" Hidden="FALSE" Scope="Farm" ActivateOnDefault="TRUE" xmlns="http://schemas.microsoft.com/sharepoint/"> <ElementManifests> <ElementManifest Location="elements.xml"/> </ElementManifests> </Feature>

enter code here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.