Psst! Did you know DevelopmentNow is a mobile web site design agency?

Contact us for help mobilizing your site, or to sign up for our beta Mobile Web SDK!
all groups > dotnet windows forms > september 2004 >

dotnet windows forms : Structure analogous to web.config in a windows application???


Novice
9/20/2004 1:35:04 PM
Hey everyone - is there a file in a windows application that is analogous to
the web.config in ASP.NET applications?

Basically, I want to store a bunch of strings (that are NOT confidential) in
a common configuration file and that I can easily access like the web.config
file for ASP.NET applications.

In summary I would like a place to store configuration information for a
windows application and the methods I use to access that information.

Thanks,
Matt Berther
9/20/2004 1:46:30 PM
Hello Novice,

Using VS.NET, create a file named App.config. If not using VS.NET, create a file named YourExecutableName.exe.config.

The format of this file and method to access it are analogous to the web.config.

--
Matt Berther
http://www.mattberther.com

[quoted text, click to view]
Matt Berther
9/21/2004 2:18:00 PM
Hello Tal,

Why would you use AppSettingsReader instead of ConfigurationSettings.AppSettings?

--
Matt Berther
http://www.mattberther.com

[quoted text, click to view]
Tal Sharfi
9/22/2004 12:00:36 AM
hi

you can use the App.Config file. if you don'a have it yet on your project,
then, right click the project in the solution explorer->add new item->
choose 'Application Configuration'.
then edit it to something like:
<?xml version="1.0" encoding="utf-8" ?>

<configuration>

<appSettings>

<add key="MyKey" value="MyData" />

</appSettings>

</configuration>

and then you can access the data in the code by using:
using System.Configuration;

AppSettingsReader appSettings = new AppSettingsReader();

objetc = appSettings.GetValue("MyKey",typeof(System.String));



hope that will help

Tal Sharfi



[quoted text, click to view]

talsharf NO[at]SPAM hotmail.com
9/22/2004 1:07:54 AM
Hi Matt

No special reason, I just found it on the Microsoft's book:
Developing Windows-Based Applications with Microsoft Visual Basic
..NET, and Microsoft Visual C#

Chapter 9, Lesson2, somewhere in the middle:

Quoting:
To retrieve data from the configuration file manually
Create a new instance of System.Configuration.AppSettingsReader.

Use the AppSettingsReader.GetValue method to retrieve the value for
the specified key.

Convert the object returned by AppSettingsReader.GetValue to the
appropriate data type.

End of quote


I didn't check but I guess that the other method work just fine
also... :-)

Cheers,
Tal

[quoted text, click to view]
AddThis Social Bookmark Button