1
votes

Which is the best way to reference current site/web in sharepoint specially for Timer Jobs from the examples given below and why?

Example1: SPWebApplication webApp = this.Parent as SPWebApplication; SPWeb oWeb = webApp.Sites[0].RootWeb;

OR

Example2: using(SPSite site=new SPSite(SPCOntext.Current.Web.Url)){ using(SPWeb web=site.OpenWeb()){

} }

1

1 Answers

0
votes

You will not get SPContext object in Timer Job. So you have to use the first option. Or if you know the name you can pass it like this.webapplication.sites [site name]

Or you can read from the config file of timer job.