app.config

G

genc ymeri

1. How can I read/write data from app.config ?

2. Where are suppose to placed the app.config and application exe file in
the users's PC, in the same directory ? ( in my VS solution the exe and the
app.config are not in the same directory that's why I wonder how they will
be deployed/copied/installed in the user's PC?)

Thank You in advance.
 
C

chad [at] gosigma.com

Visual Studio automatically copies and renames the App.config file to be
in the same directory as the executable, and the name becomes
(appname).exe.config. This file must be in the same folder for it to be
read automatically.

Chad Evans
 
F

Fitim Skenderi

Hi

1. check the code below (in c#):

using System;
using System.Configuration;

namespace test
{
public class ConfigSettings
{
public ConfigSettings()
{
}

public string LoadConfig()
{
string settings = "";

settings = ConfigurationSettings.AppSettings.Get("mySetting");
return settings;
}
}
}

--- and your app.config has to have ----

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="mySetting" value="some string value" />
</appSettings>
</configuration>


2. app.config has to be in the sam folder as you exe file. The name of the
config file has to be the same as the application (case sensitive) but with
the .config extension. ie if your application is called app.exe then your
config file has to be called app.exe.config

hope this helps

Fitim Skenderi
 
N

Nicholas Paldino [.NET/C# MVP]

genc,

To access the .config file, you would use the ConfigurationSettings
class in the System.Config namespace.

As for your second question, yes, you should place the assembly and the
configuration file in the same directory. The runtime won't pick up the
configuration file otherwise (at least, by default, AFAIK).

Hope this helps.
 
G

genc ymeri

Faleminderit o Fitim.

Fitim Skenderi said:
Hi

1. check the code below (in c#):

using System;
using System.Configuration;

namespace test
{
public class ConfigSettings
{
public ConfigSettings()
{
}

public string LoadConfig()
{
string settings = "";

settings = ConfigurationSettings.AppSettings.Get("mySetting");
return settings;
}
}
}

--- and your app.config has to have ----

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="mySetting" value="some string value" />
</appSettings>
</configuration>


2. app.config has to be in the sam folder as you exe file. The name of the
config file has to be the same as the application (case sensitive) but with
the .config extension. ie if your application is called app.exe then your
config file has to be called app.exe.config

hope this helps

Fitim Skenderi
 
G

genc ymeri

thanks a lot :)
Nicholas Paldino said:
genc,

To access the .config file, you would use the ConfigurationSettings
class in the System.Config namespace.

As for your second question, yes, you should place the assembly and the
configuration file in the same directory. The runtime won't pick up the
configuration file otherwise (at least, by default, AFAIK).

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

genc ymeri said:
1. How can I read/write data from app.config ?

2. Where are suppose to placed the app.config and application exe file in
the users's PC, in the same directory ? ( in my VS solution the exe and the
app.config are not in the same directory that's why I wonder how they will
be deployed/copied/installed in the user's PC?)

Thank You in advance.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top