Tags

,

  • SharePoint timer job is running in different process named OWSTIMER.EXE.

  • SharePoint web application or site will run with the help of process W3WP.EXE.

  • So, the application configuration file is associated with the W3WP.EXE, so there is no way to access the web.config file in the owstimer.exe process at all. The context is completely different and out of domain. So, we need to call or access the web.config file explicitly in timer job. How to?

  • Remember, always C# is completely object oriented and you can access everything through objects.

  • Usually the timer job installed as a feature. And all the logic of the timer job will go inside the Execute() method. So, write below statements in that method and access the complete web.config file. Below is the example of accessing appsettings.

  • SPWebApplication webApplication = this.Parent as SPWebApplication;  
    Configuration config = WebConfigurationManager.OpenWebConfiguration("/", webApplication.Name);  
    String appValue = config.AppSettings.Settings["appSettingKey"].Value; 

     

    WebConfigurationManager is the class which is in the namespace Systen.Web.Configuration. This way, you can access the config settings from a web.config of a SharePoint web site.

    Advertisements