You'll have to read it in like any other xml file. This is chopped out
of a larger function, but you get the idea:
XmlDocument configXmlDoc = new XmlDocument();
configXmlDoc.Load("web.config");
XmlNodeList oList =
configXmlDoc.SelectNodes("configuration/appSettings/add");
for(int i = 0; i < oList.Count; i++)
{
XmlAttribute oKey = oList[i].Attributes["key"];
XmlAttribute oValue = oList[i].Attributes["value"];
if(oKey.Value == "ConnectionString")
{
// parse conn string
Regex connStringRegex = new
Regex("SERVER=(.*);DATABASE=(.*);UID=(.*);PWD=(.*) ;",
RegexOptions.IgnoreCase);
Match match = connStringRegex.Match(oValue.Value);
dbServerText.Text = match.Groups[1].Captures[0].ToString();
dbNameText.Text = match.Groups[2].Captures[0].ToString();
dbUserText.Text = match.Groups[3].Captures[0].ToString();
dbPasswordText.Text = match.Groups[4].Captures[0].ToString();
}
}
// write the config settings
XmlNodeList oList =
configXmlDoc.SelectNodes("configuration/appSettings/add");
for(int i = 0; i < oList.Count; i++)
{
XmlAttribute oKey = oList[i].Attributes["key"];
XmlAttribute oValue = oList[i].Attributes["value"];
if(oKey.Value == "ConnectionString")
{
oValue.Value =
string.Format("SERVER={0};DATABASE={1};UID={2};PWD ={3};",
dbServerText.Text, dbNameText.Text, dbUserText.Text,
dbPasswordText.Text);
}
}
configXmlDoc.Save("Web.config");
-Jason
vadim wrote:
Thank you, everybody for your replies.
The idea is to configure database connections and write the configuration
information into web.config, the utility will be used by end users. They
will install the ASP.NET application and the utility will be also installed
into the same directory. They will run the utility and it will create
encrypted entries in web.config. I want to make it as easy for the end user
as possible, I wouldn't want to go into registry.
I used to do the same thing with ini files for win 32 applications, it was
easy to write encrypted database connection settings into ini files from a
program that does encryption.
The information is static because the db connections will be very seldom
reconfigured.
"vadim" <va***@domain.com> wrote in message
news:icvoc.430681$Pk3.140361@pd7tw1no...
Hi,
Is there a .Net control available that allows to write into web.config
file
appsettings section?
The idea is to create encrypted user name and password for database
connection and then use them from ASP.Net. The program that will create
the
encrypted entries is a simple winform app.
ConfigurationSettings.appsettings allows to read web.config sections but
how
to write there?
Thank you
Vadim