Software Programs and Projects

This Software Programs and Projects include programing tips and technology using different languages like VC++,ASP,JSP C#.Net,PHP,VB.Net,JavaScript,ASP.NET .Software Programs and Projects blog mainly support to software programmers and provide help through the mail.

How can Read/Write in App.Config File using C#.Net

1.Create app.config File

<add key="EMConnectionstring" value="Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source = D:EventManagementSystem.mdb" />

2. Add new reference "System.Configure" dll

using System.Configuration;

// Open App.Config of executable
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

//ConfigurationSettings.AppSettings.

string value = string.Empty;
foreach (string key in ConfigurationManager.AppSettings)
{
value = ConfigurationManager.AppSettings[key].ToString();
}

config.AppSettings.Settings.Add("EMConnectionstring", value);

// Save the changes in App.config file.

config.Save(ConfigurationSaveMode.Modified);

// Force a reload of a changed section.

ConfigurationManager.RefreshSection("appSettings");