如何为SharePoint计时器作业设置我的Feature.xml?

时间:2010-11-19 21:59:10

标签: sharepoint sharepoint-timer-job

我有一个这样的课程:

namespace SharePointSocialNetworking
{   
    public class FeatureToEnableJob : SPFeatureReceiver
    {
      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 == "SPFacebookJob")
                job.Delete();
        }

        // Install the job.
        Facebook fbJob = new Facebook();

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

        fbJob.Update();
      }
      ...
    }

}

这是我的特色XML:

<?xml version="1.0" encoding="utf-8"?>
<Feature xmlns="http://schemas.microsoft.com/sharepoint/" 
 Id="b9e40341-32ab-410a-a20f-282cf13fb54b" 
 ReceiverAssembly="SharePointSocialNetworking, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6264b0911592ad29" 
 ReceiverClass="SharePointSocialNetworking.FeatureToEnableJob" 
 Scope="Farm" 
 Title="SharePoint Social Networking Job">
</Feature>

我的程序集称为SharePointSocialNetworking。我在这里做错了吗?

我已经完成了所有适当的设置,但是当我运行此命令时:

 stsadm -o installfeature -name SharePointSocialNetworking

我收到错误:

Object reference not set to an instance of an object.

1 个答案:

答案 0 :(得分:0)

您的功能父级不是网站而是服务器场,您不应将其强制转换为SPSite

相关问题