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

I am trying to debug a timer job, its WEB application scoped.

When it executes, webapp and sitecollections are null for some reason?

Any idea?

Update1: I changed a little bit the code, check screenshot 2, webAPP is not returning null anymore, but .SITES property is throwing an argument exception, and when I try to get the RootWeb for each site collection I also get the same exception.

I havent been able to iterate on all site collections as I want

enter image description here

enter image description here

share|improve this question
    
I just noticed that my sitecollections could be in different content databases. that might change the story over here –  L.V. Sharepoint Architect Apr 2 '12 at 9:38
    
If accessing Sites and RootWeb throws an exception how did you then get to the point where we see the code? Are you sure you're running the updated code (remember to restart the timer service)? –  Per Jakobsen Apr 2 '12 at 18:03
    
Indeed, I asked the same thing in another place, it was really strange, then in the other place they suggested to restart the timer service. and I could past forward. –  L.V. Sharepoint Architect Apr 2 '12 at 21:05
add comment

2 Answers

up vote 3 down vote accepted

Timer Jobs run as a background service and thus do not have the context of a Web Application. If you need to access a specific web app in your timer job then you will need to open the site using the usual SPSite site = new SPSite(siteurl) way and then reference the Web Application as site.WebApplication

share|improve this answer
    
I noticed this, what I did is to add to the property bag of the job definition the urls as List<string> of all site collections I want to process inside the timer job, then in the execute method I deserialize the list and I can create instances of SPSite. It was difficult to notice. but I got it now. –  L.V. Sharepoint Architect Apr 2 '12 at 21:06
add comment

Give feature scope to "WebApplication" and activate feature on specific webapplication, which shows reference to webapplication in case of "this.Parent as SPWebApplication"

share|improve this answer
add comment

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.