473,398 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

writing config-file

MK
Is there any way to write into the app config at runtime?

I want to store position, height and width of my forms.
Nov 15 '05 #1
2 12683
This code should do:

// use reflection to find the location of the config file
System.Reflection.Assembly asm =
System.Reflection.Assembly.GetExecutingAssembly ();
System.IO.FileInfo fi = new System.IO.FileInfo
(String.Format ("{0}.config", asm.Location));
if (!fi.Exists)
throw new Exception ("Missing config file");

// load the config file into the XML DOM.
System.Xml.XmlDocument xmlConfig = new System.Xml.XmlDocument
();
xmlConfig.PreserveWhitespace = true;
xmlConfig.Load (fi.FullName);

// find the right node and change it to the new value
foreach (System.Xml.XmlNode node in
xmlConfig["configuration"]["appSettings"])
{
if ((node.Name == "add") &&
(node.Attributes.GetNamedItem ("key").Value ==
"Height"))
{
node.Attributes.GetNamedItem ("value").Value =
newHeight;
}
< similar blocks for other parameters >
}

// write out the new config file
xmlConfig.Save (fi.FullName);

Eliyahu

"MK" <mi************@encorus.com> wrote in message
news:00****************************@phx.gbl...
Is there any way to write into the app config at runtime?

I want to store position, height and width of my forms.

Nov 15 '05 #2
Eliyahu,

Thanks for the code sample. I am pretty new at this but why did you use:

System.Reflection.Assembly asm =
System.Reflection.Assembly.GetExecutingAssembly ();
System.IO.FileInfo fi = new System.IO.FileInfo
(String.Format ("{0}.config", asm.Location));

rather than:
AppDomain.CurrentDomain.GetData("APP_CONFIG_FILE")

thanks,

dlr

"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:eg**************@TK2MSFTNGP12.phx.gbl...
This code should do:

// use reflection to find the location of the config file
System.Reflection.Assembly asm =
System.Reflection.Assembly.GetExecutingAssembly ();
System.IO.FileInfo fi = new System.IO.FileInfo
(String.Format ("{0}.config", asm.Location));
if (!fi.Exists)
throw new Exception ("Missing config file");

// load the config file into the XML DOM.
System.Xml.XmlDocument xmlConfig = new System.Xml.XmlDocument
();
xmlConfig.PreserveWhitespace = true;
xmlConfig.Load (fi.FullName);

// find the right node and change it to the new value
foreach (System.Xml.XmlNode node in
xmlConfig["configuration"]["appSettings"])
{
if ((node.Name == "add") &&
(node.Attributes.GetNamedItem ("key").Value ==
"Height"))
{
node.Attributes.GetNamedItem ("value").Value =
newHeight;
}
< similar blocks for other parameters >
}

// write out the new config file
xmlConfig.Save (fi.FullName);

Eliyahu

"MK" <mi************@encorus.com> wrote in message
news:00****************************@phx.gbl...
Is there any way to write into the app config at runtime?

I want to store position, height and width of my forms.


Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Daniel Caetano | last post by:
Is that possible change attributes values that belong the app.config? Example i want to change the <ConfigProvider> encrypted="true" to "false". Can somebody help me???
16
by: Frank Oquendo | last post by:
ConfigurationSettings.AppSettings allows me to read from my config but how do I write to my config file? -- There are 10 kinds of people. Those who understand binary and those who don't. ...
3
by: Anders Both | last post by:
How can i setup my system so that I can write into the eventLog from the asp.net process. I tryid to add the asp.net account to administrator group, but that does not help. ???
6
by: MattC | last post by:
I have some code that correctly writes to the eventlog on my local machine. I have installed the application on the Live server and all is not well, no event log entries. My development box...
6
by: rekaeps | last post by:
We are developing an ASP.NET 2.0 (C#) application, and I'm having troubles sending e-mail from the server when accessing the web site from a separate client computer. Also, in the same scenario,...
9
by: WT | last post by:
Hello, I am writing a Web install project and I want to get the connection string from user and write it in the web.config of the installed web site. As the Websetup is a windows program, I use...
6
by: c00i90wn | last post by:
Hey, I'm having a problem with the xml.dom.minidom package, I want to generate a simple xml for storing configuration variables, for that purpose I've written the following code, but before pasting...
0
by: vishalsharma | last post by:
hi i am having problem when i am trying to write something on remote location using .net thread. e.g. i have a central location letsay MachineName|MachineIP/SharedDrive. and i am creating a...
1
by: sam | last post by:
Hi, I use string sValue = ConfigurationManager.AppSettings for reading a value in my app.config, section AppSettings. Ho to write in it for example to create a key and assign a value like this ?...
10
by: jimjim | last post by:
HI, We have shifted our database from sqlserver2003 to sqlserver2005. 1. connection strings stored in web.config <!-- Machine name to connection string keys --> <add key="*777*"...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.