private void SetConfigSettings()
{
try
{
//
App setting settings
System.Configuration.Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
//APPsetting
value change
System.Configuration.KeyValueConfigurationElement setting =
config.AppSettings.Settings["SupportFormat"];
if
(null != setting)
config.AppSettings.Settings["SupportFormat"].Value
= txtFormat.Text.Trim();
//APPsetting
value change
System.Configuration.KeyValueConfigurationElement Pathsetting =
config.AppSettings.Settings["Path"];
if
(null != Pathsetting)
config.AppSettings.Settings["Path"].Value
= txtPath.Text.Trim();
//Connection
string changes
string
newConnectionString = "Data Source="
+ txtServer.Text + ";Initial Catalog='"
+ txtDatabaseName.Text.Replace("'",
"") + "';User
ID=" + txtUserName.Text + ";Password="
+ txtPassword.Text + ";Persist Security
Info=True;";
//Configuration
openWebConfiguration =
WebConfigurationManager.OpenWebConfiguration("~");
ConnectionStringsSection
sections = config.GetSection("connectionStrings")
as ConnectionStringsSection;
if
(sections != null)
{
sections.ConnectionStrings["ConString"].ConnectionString =
newConnectionString;
ConfigurationManager.RefreshSection("ConString");
}
config.Save();
lblMSG.Text = "Updated successfully!!!";
lblMSG.ForeColor = Color.Green;
}
catch
(System.Exception exc)
{
lblMSG.Text = exc.Message;
lblMSG.ForeColor = Color.Red;
}
}
No comments:
Post a Comment