I'm writing a timer job that needs to email document owners when a document column (review Date=today) I want features to be available in sites which I can activate site collection.
How do I ensure that the site where I activate the feature is the site that gets iterated. I've done this in the past but used absolute url's
i.e. SPSite site = webApplication.Sites[http];However I dont want to give any specific urls as I want one feature available on numerous sites in a single site collection.
Could someone help with method to use and getting a reference for the site where activated and iterating list in that site pls? I found the following pieces of code:
public override void Execute(Guid contentDbId)
{
// 1 here }
or
public override void Execute(Guid targetInstanceId)
{
// 2 here }
Code found to iterate a list https://stackoverflow.com/questions/965695/iterate-a-sharepoint-list
public override void FeatureActivated(SPFeatureReceiverProperties properties) { using(SPSite site = properties.Feature.Parent as SPSite) { SPList list = site.RootWeb.Lists["ListName"]; SPListItemCollection items = list.Items; foreach (SPListItem listItem in items) { Response.Write(SPEncode.HtmlEncode(listItem["Url"].ToString()) +"
"); } } }
I also have a feature in the project (can this be used to gather the path of activated site?
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 == List_JOB_NAME1) job.Delete(); } // install the job ReviewDocument ListTimerJob1 = new ReviewDocument("ReviewDate", site.WebApplication); }