Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Completley new to sp and trying to create a timer job that uses a value stored in a persisted object. I found some examples but for some reason when my job runs the persisted object is always null. My code is below

code to retrieve the object

 ContentDataBaseIncrementorJobSettings Settings = WebApplication.GetChild<ContentDataBaseIncrementorJobSettings>(ContentDataBaseIncrementorJobSettings.SettingsName);

 if (Settings == null) {
      return;
}

code in the feature activated event

        ContentDataBaseIncrementorJobSettings ContentDataBaseIncrementorJobSettings =
            WebApplication.GetChild<ContentDataBaseIncrementorJobSettings>(ContentDataBaseIncrementorJobSettings.SettingsName);

        //only create a new settings object if there isnt one.
        if (ContentDataBaseIncrementorJobSettings == null) {
            ContentDataBaseIncrementorJobSettings = new ContentDataBaseIncrementorJobSettings(WebApplication, Guid.NewGuid());
            ContentDataBaseIncrementorJobSettings.CurrentIncrement = 10;
            ContentDataBaseIncrementorJobSettings.Update();
        }

my persisted object definition

   public class ContentDataBaseIncrementorJobSettings : SPPersistedObject {
            public static string SettingsName = "ContentDatabaseIncrementorTimerJobSettings";

            public ContentDataBaseIncrementorJobSettings() : base() { }
            public ContentDataBaseIncrementorJobSettings(SPPersistedObject parent, Guid id) : base(SettingsName, parent, id) { }

            [Persisted]
            public int CurrentIncrement;
        }
share|improve this question

1 Answer 1

As per MSDN thread "To return an existing persisted object, use the GetObject method of the SPFarm class, or the GetChild method of the SPPersistedObject class". Try using WebApplication.SPFarm.GetObject()

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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