Error Reading App.config
resources Windows Server 2012 resources Programs MSDN subscriptions Overview Benefits Administrators Students Microsoft Imagine Microsoft Student Partners ISV Startups TechRewards Events Community Magazine Forums Blogs Channel 9 Documentation APIs and reference Dev centers Retired content Samples We’re sorry. The content you requested has been removed. You’ll be auto redirected in 1 second. System.Configuration ConfigurationManager Class ConfigurationManager Properties ConfigurationManager Properties AppSettings Property AppSettings Property AppSettings Property AppSettings Property ConnectionStrings Property TOC Collapse the table of content Expand the table of content This documentation is archived and is not being maintained. This documentation is archived and is not being maintained. ConfigurationManager.AppSettings Property .NET Framework (current version) Other Versions Visual Studio 2010 .NET Framework 4 Visual Studio 2008 .NET Framework 3.5 .NET Framework 3.0 .NET Framework 2.0 Gets the AppSettingsSection data for the current application's default configuration.Namespace: System.ConfigurationAssembly: System.Configuration (in System.Configuration.dll)Syntax C#C++F#VB Copy public static NameValueCollection AppSettings { get; } Property Value Type: System.Collections.Specialized.NameValueCollectionReturns a NameValueCollection object that contains the contents of the AppSettingsSection object for the current application's default configuration. Exceptions Exception Condition ConfigurationErrorsExceptionCould not retrieve a NameValueCollection object with the application settings data.RemarksA AppSettingsSection object contains the contents of the configuration file's appSettings section.ExamplesThe first example shows a simple console application that reads application settings, adds a new setting, and updates an existing setting. C#VB Copy using System; using System.Configuration; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { ReadAllSettings(); ReadSetting("Setting1"); ReadSetting("NotValid"); AddUpdateAppSettings("NewSetting", "May 7, 2014"); AddUpdateAppSettings("Setting1", "May 8, 2014"); ReadAllSettings(); } static void ReadAllSettings() { try { var appSettings = ConfigurationManager.AppSettings; if (appSettings.Count == 0) { Console.WriteLine("AppSettings is empty.");
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only https://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.appsettings(v=vs.110).aspx takes a minute: Sign up AppSettings get value from .config file up vote 68 down vote favorite 5 I'm not able to access values in configuration file. Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); var clientsFilePath = config.AppSettings.Settings["ClientsFilePath"].Value; // the second line gets a NullReferenceException .config file:
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this http://stackoverflow.com/questions/18159667/error-while-reading-connectionstring-from-app-config-file site About Us Learn more about Stack Overflow the company Business Learn http://stackoverflow.com/questions/15143057/write-read-app-config-setting more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Error error reading while reading ConnectionString from App.config file up vote 1 down vote favorite I have this App.config file:
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Write & Read App Config Setting up vote 1 down vote favorite I have an application that need to check to the database if a particular code exists; if it does exist, then have to load the corresponding value of that code else return null. I don't want to hit the database for each code(running about 200.000 codes ). so i got this small app to test the app.conf public static void setAppSetting(string key, string value) { Configuration config = ConfigurationManager.OpenExeConfiguration(System.Reflection.Assembly.GetExecutingAssembly().Location); if (config.AppSettings.Settings != null) { config.AppSettings.Settings.Remove(key); } config.AppSettings.Settings.Add(key, value); config.Save(ConfigurationSaveMode.Modified); } public static string getAppSetting(string key) { try { Configuration config = ConfigurationManager.OpenExeConfiguration(System.Reflection.Assembly.GetExecutingAssembly().Location); return config.AppSettings.Settings[key].ToString(); } catch (Exception ex) { throw ex; } } private static void loadKeysValues() { using (SqlConnection Gcon = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["constr"].ConnectionString)) { //Open Connection Gcon.Open(); using (SqlCommand sqlCmd = new SqlCommand("SELECT key,value FROM tables", Gcon)) { using (SqlDataReader reader