Click to See Complete Forum and Search --> : Configuration File


Joch
October 7th, 2005, 03:38 AM
Hi,

I want to store a UserID in a Configuration File so that my program can get it.
My program is called "config_File_test.exe" and the name of the Configuration file is "config_File_test.exe.config". The content of the Configuration file is:

<configuration>
<appSettings>
<add key="userID" value="js" />
</appSettings>
</configuration>

If I put this file in the \bin directory it is deleted when I build my project, but I read that it has to be in this directory. If I put the file there after compiling the project in doesn't work anyway.

I use the following coding to read the userID form the file:

Dim x As String
x = Configuration.ConfigurationSettings.AppSettings.Get("userID")
MsgBox(x)

When debugging it says "x=Nothing".

I'm using Visual Studio .Net 2003.

Can anybody tell me how I can solve this problem?

Joch

Shuja Ali
October 7th, 2005, 04:35 AM
when you create a Config file for a particular project, it is saved in the Project Folder and not the BIN folder. The Config file that is created is named as App.config (That is if you add it using the Project Menu/Solution explorer.

When you build the project the Config file automatically gets copied over to the BIN folder and is renamed to application.exe.config.

Your code is perfect, only thing you need to do is create a app.config file in your project folder and then run the project.

Joch
October 7th, 2005, 06:21 AM
Hi Shuja Ali,

thanks for your help, now it works.

Jochen