473,657 Members | 2,515 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 12693
This code should do:

// use reflection to find the location of the config file
System.Reflecti on.Assembly asm =
System.Reflecti on.Assembly.Get ExecutingAssemb ly ();
System.IO.FileI nfo fi = new System.IO.FileI nfo
(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.XmlD ocument xmlConfig = new System.Xml.XmlD ocument
();
xmlConfig.Prese rveWhitespace = true;
xmlConfig.Load (fi.FullName);

// find the right node and change it to the new value
foreach (System.Xml.Xml Node node in
xmlConfig["configurat ion"]["appSetting s"])
{
if ((node.Name == "add") &&
(node.Attribute s.GetNamedItem ("key").Valu e ==
"Height"))
{
node.Attributes .GetNamedItem ("value").Va lue =
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.Reflecti on.Assembly asm =
System.Reflecti on.Assembly.Get ExecutingAssemb ly ();
System.IO.FileI nfo fi = new System.IO.FileI nfo
(String.Format ("{0}.config ", asm.Location));

rather than:
AppDomain.Curre ntDomain.GetDat a("APP_CONFIG_F ILE")

thanks,

dlr

"Eliyahu Goldin" <re************ *@monarchmed.co m> wrote in message
news:eg******** ******@TK2MSFTN GP12.phx.gbl...
This code should do:

// use reflection to find the location of the config file
System.Reflecti on.Assembly asm =
System.Reflecti on.Assembly.Get ExecutingAssemb ly ();
System.IO.FileI nfo fi = new System.IO.FileI nfo
(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.XmlD ocument xmlConfig = new System.Xml.XmlD ocument
();
xmlConfig.Prese rveWhitespace = true;
xmlConfig.Load (fi.FullName);

// find the right node and change it to the new value
foreach (System.Xml.Xml Node node in
xmlConfig["configurat ion"]["appSetting s"])
{
if ((node.Name == "add") &&
(node.Attribute s.GetNamedItem ("key").Valu e ==
"Height"))
{
node.Attributes .GetNamedItem ("value").Va lue =
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
1077
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
16452
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. http://code.acadx.com (Pull the pin to reply)
3
10473
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
1707
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 config is as follows: Windows XP Pro running IIS 5.1 Web app using integrated auth using a local user account Account has admin right over machine. Entry has been placed in registry in
6
2523
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, I'm having trouble writing to the server's event log. Here's some details: Server and workstation both in the same workgroup Logged into server as local Administrator Logged into workstation as a local user that is only in the Users group on
9
3781
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 a windows program to get the string and I don't know if I can use the WebConfigurationManager API to read and write my web config from a windows program. What is the prefered .NET 2 way to handle this necessary install problem without asking...
6
1979
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 it I'll tell you what my problem is. On first write of the xml everything goes as it should but on subsequent writes it starts to add more and more unneeded newlines to it making it hard to read and ugly. Here is the code that you can test by...
0
782
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 thread on click of a button which i need to write some information on that location. i have also added a node <identity impersonate="true" userName="Domain\User" password="*******"/> in web.config of my application. and i have also given...
1
1946
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 ? ConfigurationManager.AppSettings="my value in app.config"; Thanks for help. Sam
10
2308
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*" value="**ConnString_DEV" /> <add key="server2" value="**ConnString_TST" /> <add key="server1" value="**ConnString_PRD" /> <!-- Literal Connection String Keys -->
0
8392
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8305
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8825
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7324
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4302
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.