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 thought I could reference SPContext when executing the timerjob function but I get "Instance reference is not set to an instance of an object". It fails when I reference SPContext.

What am I doing wrong? (I'm trying to update items in a list using a TimerJob)

Public Overrides Sub Execute(ByVal targetInstanceId As Guid)

   Dim oWeb As SPWeb = SPContext.Current.Web
   oWeb.Site.OpenWeb("http://dept.litwareinc.com/npp/NPE")

   'Update PEEIT Employees List
   UpdatePEEITEmployees(oWeb)

End Sub
share|improve this question
    
Please accept the answer if it resolves, yours is 0% (Accept rate) –  Vamsi Nov 7 '11 at 20:04
add comment

2 Answers

SPContext is not accessible in timer job. The SharePoint timer service is a windows service. So you should pass a site and web Ids(Urls) to the timer job and open new web.

using(SPSite site = new SPSite(siteId)){using(SPWeb web = site.OpenWeb(webId)) { //code }}
share|improve this answer
add comment

SPContext represents the context of a HTTPRequest (Similar to HTTPContext).

In the Execute method, SPWebApplication instance is available ; get the target site instance from the this.WebApplication.Sites collection.

URL : http://msdn.microsoft.com/en-us/library/cc406686%28v=office.12%29.aspx

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.