Search This Blog

Monday, November 11, 2013

Reading SharePoint web.config

Usage Scenarios:
Read configuration information like SQL connection string, custom application settings etc. from SharePoint web.config file
Here is the code snippet:
using System.Configuration;
using System.Web.Configuration;
string webAppName = SPContext.Current.Site.WebApplication.Name;  // use SPSite object hierarchy to get web application name.
Configuration config = WebConfigurationManager.OpenWebConfiguration("/", webAppName);
string dataFromAppSettings = config.AppSettings.Settings["Setting Name to read"].Value;


That's all for this post. Until next time...

-- Mohan

No comments: