only My site

Sunday, April 1, 2012

SPContext Replacement in Timer Jobs

Recently we encountered an issue in running the code (with "SPContext") in Timer job. After doing the learning, I understood the that the SPContext will not work in

1. Timer Job
2. Event Receier
3. Console and windows application running in the servers

Solution :

The solution is

using(SPSite oSite = new SPSite(this.WebApplication.Sites[0].Url))

{

using(SPWeb oWeb = oSite.OpenWeb())

{

}

}

No comments: