我创建了一个计时器作业并将 wsp 部署到中央管理员。该功能已安装并激活正常。我没有收到任何错误。但我在中央管理员的计时器作业列表中看不到计时器作业。我也没有在网站集功能中看到该功能。
1)我确实使用 STSADM 命令安装并激活了这些功能。2) Timer 作业没有出现在 sharepoint manager 的 Job Definitions 下。但是,该功能确实出现在共享点管理器中的功能定义下
Web 应用程序具有三个站点集合,每个站点集合都有一个单独的数据库数据库
安装或激活该功能时我没有收到任何错误。
MY code is as follows
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
namespace TestTimer
{
public class TestTimerJob:SPJobDefinition
{
public TestTimerJob() : base()
{
}
public TestTimerJob(string jobName, SPService service, SPServer server, SPJobLockType targetType)
: base(jobName, service, server, targetType)
{
this.Title = "Test Timer Job";
}
public TestTimerJob(string jobName, SPWebApplication webApplication)
: base(jobName, webApplication, null, SPJobLockType.Job)
{
this.Title = "Test Timer Job";
}
public override void Execute(Guid targetInstanceId)
{
try
{
SendEmail();
}
catch (Exception ex)
{
LogError(ex.InnerException.ToString(), ex.StackTrace + ex.Source);
}
}
private void SendEmail()
{
try
{
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
//msg.To.Add(ToEmailAddress);
msg.To.Add("****");
msg.From = new System.Net.Mail.MailAddress(""********";");
msg.Subject = "Subject";
msg.IsBodyHtml = true;
string 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);
}
}
}
}
Feature Reciever code below
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using System.Data.SqlClient;
namespace TestTimer
{
class TestTimerReceiver : SPFeatureReceiver
{
const string SYNC_JOB_NAME = "My_Timer_Job";
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
try
{
SPWebApplication webapp = (SPWebApplication)properties.Feature.Parent;
foreach (SPJobDefinition job in webapp.JobDefinitions)
{
if (job.Name.ToLower()==SYNC_JOB_NAME.ToLower())
{
job.Delete();
}
}
TestTimerJob timerJob = new TestTimerJob(SYNC_JOB_NAME, webapp);
SPMinuteSchedule schedule = new SPMinuteSchedule();
schedule.BeginSecond = 0;
schedule.EndSecond = 59;
schedule.Interval = 5;
timerJob.Schedule = schedule;
timerJob.Update();
}
catch (Exception ex)
{
}
}
public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
try
{
SPWebApplication webapp = (SPWebApplication)properties.Feature.Parent;
foreach (SPJobDefinition job in webapp.JobDefinitions)
{
if (job.Name.ToLower()==SYNC_JOB_NAME.ToLower())
{
job.Delete();
}
}
}
catch (Exception ex)
{
}
}
public override void FeatureInstalled(SPFeatureReceiverProperties properties)
{
}
public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
{
}
}
}
和下面的功能 .xml
<?xml version="1.0" encoding="utf-8"?>
<Feature Id="b4fa9cf0-dba9-4206-a37c-e707af6199f9"
Title="TestTimerReceiver"
Description="Description for TestTimerReceiver"
Version="12.0.0.0"
Hidden="FALSE"
Scope="Site"
DefaultResourceFile="core"
ReceiverAssembly="TestTimer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7f9249145d98c2ad"
ReceiverClass="TestTimer.TestTimerReceiver"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="elements.xml"/>
</ElementManifests>
</Feature>