我创建了一个Timer Job并将wsp部署到中央管理员。该功能已安装并正常启动。我没有得到任何错误。但我无法在中央管理员的计时器作业列表中看到计时器作业。我也没有看到网站集功能中的功能。
1)我使用STSADM命令安装并激活了这些功能。 2)定时器作业未出现在sharepoint管理器中的作业定义下。但是,该功能确实出现在sharepoint manager
中的功能定义下Webapplication有三个网站集,每个网站集都有一个单独的数据库数据库
安装或激活功能时,我没有收到任何错误。
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>
答案 0 :(得分:0)
还尝试清除Sharepoint服务器缓存