Tag Archives: טייַמער אַרבעט

טייַמער דזשאָב פעאַטורעאַקטיוואַטעד און פיטשער סקאָופּ

איך'ווע געווען ארבעטן מיט עטלעכע קאָד אַז עמעצער קאָלנער צו מיר פֿאַר אַ טייַמער אַרבעט.  ער האט נישט צוגעשטעלט די פאַקטיש שטריך אַקטאַוויישאַן קאָד אַזוי איך געהאט צו שרייַבן עס, פון קורס.  I took advantage of Andrew Connell’s famous blog post on the subject.

איך בין ניצן וויסואַל סטודיאָ 2010 and deployment kept failing with an error “Error occurred in deployment step ‘Add Solution’: Object reference not set to an instance of an object.”

I was taking his code too literally.  I was scoping the feature to the web application level, ווי געוויזן:

image

ווי אַ רעזולטאַט, the properties that are sent to the receiver are from the web application, not a site collection.  אין די סוף, the code looks like this:

public override void FeatureActivated(SPFeatureReceiverProperties properties)
{

    // Don’t do the following with web app scoped features, it leads to despair שמייכל
    // SPSite site = properties.Feature.Parent as SPSite;

    SPWebApplication wa = properties.Feature.Parent as SPWebApplication;

    צי (wa == null) throw new Exception("webapp2 is null.");

    פאָרעאַטש (SPJobDefinition job in wa.JobDefinitions)
    {

        פּרובירן
        {
            צי (job.Name == List_JOB_NAME)

                job.Delete();
        }
        כאַפּן (Exception e)
        {
            throw new Exception("marker 2");
        } // catch exception e
    }

    // install the job

    WeatherForecastTimerJob weatherForecastTimerJob =
        new WeatherForecastTimerJob(List_JOB_NAME, wa);

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

}

The key take-away is that when the feature is scoped to a web app, the SPFeatureReceiverProperties that SharePoint passes to your feature receiver has web app level parameters.  Andrew’s old blog entry assumes it’s scoped to the site collection.

</עק>

אַבאָנירן צו מיין בלאָג.

גיי מיר אויף טוויטטער בייַ http://www.twitter.com/pagalvin