How do I Access Sitecore settings Programmatically?

All the settings of the Sitecore are stored in the config files. Sitecore consists of web.config which stores all the configuration information. Addition to this Sitecore has many config files which are stored in the App_Config/Include folder. Most of the time’s developer place the config files to override or patch the Sitecore functionalities. So how do you Access Sitecore settings Programmatically which is present in the config file?

Access Sitecore settings Programmatically

During the runtime, Sitecore combines all these config files into one single web.config file. Hence at the runtime, we can access any of these config file settings programmatically.

To verify the web.config file Sitecore provides an admin page.

URL : http://myurl/sitecore/admin/showconfig.aspx 

The above URL will combine all the configs from App_Config/Include and displays single config file.

All the settings listed in the config file can be accessed at run time using the below code.

var mySetting=Sitecore.Configuration.Settings.GetSetting("SettingName");

Access Data Folder in Sitecore Programmatically

string dataFolder = Sitecore.Configuration.Settings.DataFolder;

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Sign Up for Our Newsletters

Subscribe to get notified of the latest articles. We will never spam you. Be a part of our ever-growing community.

You May Also Like