473,322 Members | 1,504 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,322 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 18175
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.