By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,184 Members | 1,522 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,184 IT Pros & Developers. It's quick & easy.

App.config in a Windows .NET application

P: n/a
Hi,

I am developing a windows .NET apps to be used in several countries with
different languages and I want to use a configuration file to retrieve the
fields in the right language depend on the selected country.

I saw that on a web apps but I am not sure if I can do the same on a win apps.

If someone have an idea of how to do that or give me an example about it, it
would be really appreciated

Thanks!

Sean.
Sep 14 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Just create a App.config in the root of the project directory and include it
in the project.

J
--
Be Cool!
"Sean" wrote:
Hi,

I am developing a windows .NET apps to be used in several countries with
different languages and I want to use a configuration file to retrieve the
fields in the right language depend on the selected country.

I saw that on a web apps but I am not sure if I can do the same on a win apps.

If someone have an idea of how to do that or give me an example about it, it
would be really appreciated

Thanks!

Sean.

Sep 14 '05 #2

P: n/a
>I am developing a windows .NET apps to be used in several countries with
different languages and I want to use a configuration file to retrieve the
fields in the right language depend on the selected country.
I saw that on a web apps but I am not sure if I can do the same on a win apps.


Add a straight text file called "app.config" to your project - call it
just that - nothing else. It will be copied to your compile output
directory and renamed to "myapp.exe.config" by the VS.NET IDE for you.

The app.config file has a clear structure - you can read up about it
on MSDN. Basically, you can either use just the standard <appSettings>
section, to store a few select entries, or you can define your own
custom configuration section (of standard type), or you can even write
your own custom configuration section handler to handle specific
configuration settings.

The info in the app.config file is XML - you need to adhere to all XML
rules and stuff.

Here's a sample app.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="Default Language" value="en-US" />
<add key="FieldNames" value="fieldnames.txt" />
</appSettings>
</configuration>

To read those values, add the "System.Configuration" namespace to your
using clause, and then use

string sDefaultLanguage = ConfigurationSettings.AppSettings["Default
Language"];
string sFieldNames =
ConfigurationSettings.AppSettings["FieldNames"]
As I said - I would keep the number of entries low - a few, a few
dozen at most - not more.

Marc
================================================== ==============
Marc Scheuner May The Source Be With You!
Berne, Switzerland m.scheuner -at- inova.ch
Sep 15 '05 #3

P: n/a
Hi Marc

Your info is very useful ... but I have a question: from your example how
can I read the data from your .txt file? This is that I need for my apps.

Thanks for your reply ...

Sean
"Marc Scheuner [MVP ADSI]" wrote:
I am developing a windows .NET apps to be used in several countries with
different languages and I want to use a configuration file to retrieve the
fields in the right language depend on the selected country.
I saw that on a web apps but I am not sure if I can do the same on a win apps.


Add a straight text file called "app.config" to your project - call it
just that - nothing else. It will be copied to your compile output
directory and renamed to "myapp.exe.config" by the VS.NET IDE for you.

The app.config file has a clear structure - you can read up about it
on MSDN. Basically, you can either use just the standard <appSettings>
section, to store a few select entries, or you can define your own
custom configuration section (of standard type), or you can even write
your own custom configuration section handler to handle specific
configuration settings.

The info in the app.config file is XML - you need to adhere to all XML
rules and stuff.

Here's a sample app.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="Default Language" value="en-US" />
<add key="FieldNames" value="fieldnames.txt" />
</appSettings>
</configuration>

To read those values, add the "System.Configuration" namespace to your
using clause, and then use

string sDefaultLanguage = ConfigurationSettings.AppSettings["Default
Language"];
string sFieldNames =
ConfigurationSettings.AppSettings["FieldNames"]
As I said - I would keep the number of entries low - a few, a few
dozen at most - not more.

Marc
================================================== ==============
Marc Scheuner May The Source Be With You!
Berne, Switzerland m.scheuner -at- inova.ch

Sep 15 '05 #4

P: n/a
>Your info is very useful ... but I have a question: from your example how
can I read the data from your .txt file? This is that I need for my apps.


You'd have to use the usual System.IO methods - open a file stream,
create a stream reader, read the file - there's no "magic" in the
config system to make that happen for you, sorry.

Marc
Sep 16 '05 #5

P: n/a
Hi again,

I added an apps.config file into my project but my application cannot read
the values.

Actually I have 3 project in my solution and I added this apps.config into
my data layer project to have several connection strings depending on what
data source using I am.

Can you please give me some idea why this config file is not working?

Thanks

Sean


"Marc Scheuner [MVP ADSI]" wrote:
Your info is very useful ... but I have a question: from your example how
can I read the data from your .txt file? This is that I need for my apps.


You'd have to use the usual System.IO methods - open a file stream,
create a stream reader, read the file - there's no "magic" in the
config system to make that happen for you, sorry.

Marc

Sep 16 '05 #6

P: n/a
>I added an apps.config file into my project but my application cannot read
the values.
You need to call the file "app.config" - *NOT* "apps.config" !!
Actually I have 3 project in my solution and I added this apps.config into
my data layer project to have several connection strings depending on what
data source using I am.


The app.config works *ONLY* with an EXE project - a class library
project creating a DLL assembly will *NOT* use any app.config files
(and it won't copy and rename them, either).

Marc
Sep 18 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.