473,386 Members | 1,842 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,386 software developers and data experts.

App.config in a Windows .NET application

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
6 18178
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
>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
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
>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
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
>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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Simon | last post by:
Hi everyone, I really need help with the following: It's common in app development to create numerous projects under one solution that as a whole combine to become your final application. For...
5
by: Sridhar | last post by:
Hi, I have created a project which contains classes to read the data from the database. This project has an App.Config file which contains the SqlConnection String. when this code is called from...
3
by: Richard Lewis Haggard | last post by:
I have a test application that is calling an assembly that reads some strings out of a config file. Normally, this assembly supports a web application and the information can be read just fine....
4
by: kalyankp78 | last post by:
Hi, I have a question about config files. I have the following in my application.. 1. ASP.NET web application with a web.config 2. C# class library (BL and DAL) with an App.config 3. Two...
6
by: NickP | last post by:
Hi there, I am implementing a simple "/U" command line argument for a .NET application that instructs the application to delete the following folders... ...
7
by: moondaddy | last post by:
I'm running a wpf windows app and want to add the appSettings element to the config file. when I do, the app wont start up and I get the following error: {"The type initializer for...
3
by: Blasting Cap | last post by:
I am working on a web app that I want to be able to use a separate config file on, in addition to the web.config file that's already working in the application. If I put the following in the...
12
by: dbuchanan | last post by:
Hello, (Is this the proper newsgroup?) === Background === I am building a solution with two projects. One project is my data access layer which contains my DataSet as an xsd file. The XSD...
5
by: =?Utf-8?B?SmVycnkgQw==?= | last post by:
I have a app that uses several membership/role providers. I can list these Providers with the code: Dim rootWebConfig1 As Configuration rootWebConfig1 =...
5
by: gr8Ashish | last post by:
hi all i am using a windows application as well as web application developed in visual studio 2010 beta 2 using .net framework 4 on windows xp/windows server 2008/windows7 i am...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...

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.