Access Web Config in SharePoint Timer Job


When we have a SharePoint timer and we store some information on the site web.config. The SharePoint Timer cannot by automatically access the web.config because SharePoint Timer itself have a web.config on hive folder.

To do access the Web.Config in the Sharepoint Timer here as below the script code :using

Using System.Web.Configuration;
public override void Execute(Guid contentDbId)

SPWebApplication webApplication = this.Parent as SPWebApplication;
SPContentDatabase contentDb = webApplication.ContentDatabases[contentDbId];
SPWeb webSite = contentDb.Sites[0].RootWeb;

Configuration config = WebConfigurationManager.OpenWebConfiguration(“/”, webApplication.Name);
String MSBSCConnectionString = config.ConnectionStrings.ConnectionStrings[“MSBSCConnectionString”].ConnectionString;


Happy Sharepoint-Ing 🙂


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.