read app.config

G

Guest

I have the following XML file named (applicattion.exe.config):

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<AppSettings>
<add key = "PathBD" value = "c:\project\data\maco.mdb" />
</AppSettings>
</configuration>


Can anyone send me the code for reading value of 'PathDB' please,


tanks
 
K

Kevin Hodgson

Sure Carlos,

Import System.Configuration
directorypath = ConfigurationSettings.AppSettings("PathDB")

OR

directorypath =
System.Configuration.ConfigurationSettings.AppSettings("PathDB")

Hope that helps.
Kevin
 
G

Guest

Hi,

Do you mean writing the App.Config file? This is considered bad practice, if
you need to modify the App.Config file within the application there is a
problem with the design.

Microsoft recommends to write using your own serialized object.

Hope this helps to understand .NET arch.
Salva
 
C

Chris Murphy via DotNetMonster.com

I'm not wanting to ignite a huge debate on this, but it seems to me that
NOT using [as in reading/writing/updating] the App.config file seems
counter-productive. If the INI file is considered deprecated, and practice
of using the Registry is frowned upon, they why not use the config file to
it's full potential? I'm writing a commercial application at the moment
that takes into considertation two things:

1. A user WANTS to customize a tool for their particular habits/needs
2. If the customized settings get wiped, then a default set of applications
will be needed.

To that end this is the solution that I'm following:
I've encapsulated methods for AppConfig and xml
serialization/deserialization of application settings into a couple
classes. ClassA is the Configuration manager, and ClassB is the xml
serializer/deserializer. All this is well and good, but in the event that
settings are wiped, the application simply replaces the config file with a
default copy that it stores as a resource (defaultsettings.xml) in the exe.

In my experience a simple solution like this is more than enough to deal
with business & IT requirements as well as cater to a user's needs.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top