473,386 Members | 1,753 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.

Retrieving Configuration Settings in VS2005

Dan
I use the settings grid to create a setting named "ServerName". Now i
want to retrieve it in code and i can't figure out how. This should be
incredibly obvious but i cant get it.

I have tried creating an AppSettingsReader and using
GetValue("ServerName", typeof(String)). That threw an error about key
not found. Then i tried ConfigurationManager.AppSettings["ServerName"]
but that returns blank. I supplied a value when i created the setting.

I did this in VB and C#. The VB one was easy. My.Settings returned
that value. The config files for both apps are the same.

What is the My.Settings equivalent in c#?

dan
Mar 25 '06 #1
10 6873
It would be something like this...

Properties.Settings.Default.ServerName

--
Tim Wilson
..NET Compact Framework MVP

"Dan" <da*******@bigfoot.com> wrote in message
news:eI**************@TK2MSFTNGP11.phx.gbl...
I use the settings grid to create a setting named "ServerName". Now i
want to retrieve it in code and i can't figure out how. This should be
incredibly obvious but i cant get it.

I have tried creating an AppSettingsReader and using
GetValue("ServerName", typeof(String)). That threw an error about key
not found. Then i tried ConfigurationManager.AppSettings["ServerName"]
but that returns blank. I supplied a value when i created the setting.

I did this in VB and C#. The VB one was easy. My.Settings returned
that value. The config files for both apps are the same.

What is the My.Settings equivalent in c#?

dan

Mar 25 '06 #2
Dan
Tim Wilson wrote:
It would be something like this...

Properties.Settings.Default.ServerName

That seems to return the default value only. If i change the value in
the config file the original value is still returned. Am i missing
something?

Dan
Mar 25 '06 #3
How are you changing the value in the config file?

--
Tim Wilson
..NET Compact Framework MVP

"Dan" <da*******@bigfoot.com> wrote in message
news:eW**************@TK2MSFTNGP09.phx.gbl...
Tim Wilson wrote:
It would be something like this...

Properties.Settings.Default.ServerName

That seems to return the default value only. If i change the value in
the config file the original value is still returned. Am i missing
something?

Dan

Mar 25 '06 #4
Dan
The value that is returned is always the value specified by the
attribute DefaultSettingValueAttribute.

The values in the config files (app.config, LibraryConfig.dll.config in
the debug directory and the one of the same name in the exe path) all
have different values.

I have a C# Class Library that gets a setting and is accessed by an vb exe.

I have been changing the values by every means possible. I have used
the VS IDE and a text editor.

I can seem to find any help on MSDN or google on this either.

Tim Wilson wrote:
How are you changing the value in the config file?

Mar 26 '06 #5
Dan
That method seems to work when the application is an executeable. If i
use this with a dll it doesn't. I have changed the file.dll.config many
times but it always uses the default. Perhaps it is looking for that
value in a different config file.

dan
Dan wrote:
The value that is returned is always the value specified by the
attribute DefaultSettingValueAttribute.

The values in the config files (app.config, LibraryConfig.dll.config in
the debug directory and the one of the same name in the exe path) all
have different values.

I have a C# Class Library that gets a setting and is accessed by an vb exe.

I have been changing the values by every means possible. I have used
the VS IDE and a text editor.

I can seem to find any help on MSDN or google on this either.

Tim Wilson wrote:
How are you changing the value in the config file?

Mar 26 '06 #6
Dan
I think i figured it. The file.dll.config needs to be merged with the
exe's config file. why does the IDE create file.dll.config if it needs
to be merged with file.exe.config?

Very unintuitive.

dan

Dan wrote:
That method seems to work when the application is an executeable. If i
use this with a dll it doesn't. I have changed the file.dll.config many
times but it always uses the default. Perhaps it is looking for that
value in a different config file.

dan
Dan wrote:
The value that is returned is always the value specified by the
attribute DefaultSettingValueAttribute.

The values in the config files (app.config, LibraryConfig.dll.config
in the debug directory and the one of the same name in the exe path)
all have different values.

I have a C# Class Library that gets a setting and is accessed by an vb
exe.

I have been changing the values by every means possible. I have used
the VS IDE and a text editor.

I can seem to find any help on MSDN or google on this either.

Tim Wilson wrote:
How are you changing the value in the config file?

Mar 26 '06 #7
When you rebuild the project VS will copy the app.config file to the output
directory and rename it to [AppName.exe].config. This ensures that any
changes that you have made to the default settings through the IDE are
visible to the application when it is run. So if you change the contents of
the [AppName.exe].config file in the output directory the change(s) will be
lost next time you rebuild the application. If, however, you were to change
one of the settings through code while the application is running, assuming
that the setting is user scoped, then when the change is saved it will be
stored in a user.config file and not to the [AppName.exe].config file. For
example, if the following code was run...

Properties.Settings.Default.ServerName = "Value";
Properties.Settings.Default.Save();

.... then the new value for ServerName would be saved, by default, to a
user.config file that should be located similar to the path returned by
"System.Windows.Forms.Application.LocalUserAppData Path".

So the end result is that the settings are loaded from the
[AppName.exe].config file if it exists, otherwise they will be pulled from
the defaults, that were specified in the source code, which were compiled
into the assembly. However, if the value was changed, and saved, through
code then the settings will be loaded from the user.config file. This allows
each user to have their own settings but still be able to resort back to
defaults if necessary. You can find out more from the MSDN help.

"Application Settings for Windows Forms"
http://msdn2.microsoft.com/en-us/lib...6e(vs.80).aspx

--
Tim Wilson
..NET Compact Framework MVP

"Dan" <da*******@bigfoot.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I think i figured it. The file.dll.config needs to be merged with the
exe's config file. why does the IDE create file.dll.config if it needs
to be merged with file.exe.config?

Very unintuitive.

dan

Dan wrote:
That method seems to work when the application is an executeable. If i
use this with a dll it doesn't. I have changed the file.dll.config many
times but it always uses the default. Perhaps it is looking for that
value in a different config file.

dan
Dan wrote:
The value that is returned is always the value specified by the
attribute DefaultSettingValueAttribute.

The values in the config files (app.config, LibraryConfig.dll.config
in the debug directory and the one of the same name in the exe path)
all have different values.

I have a C# Class Library that gets a setting and is accessed by an vb
exe.

I have been changing the values by every means possible. I have used
the VS IDE and a text editor.

I can seem to find any help on MSDN or google on this either.

Tim Wilson wrote:
How are you changing the value in the config file?

Mar 26 '06 #8
E J
I think I am running into the same problem. I have multiple projects in
my solution and set an application setting for one of the project which
is not the start up project. This creates an entry a file called
app.config in that project. However, when I build the solution, the
solution.exe.config file does not contain the appliction setting I
created in the other project. Do I need to merge the app config files?
If so, how do I do that?

*** Sent via Developersdex http://www.developersdex.com ***
Apr 4 '06 #9
There are discussions on this topic within the archived newsgroup posts.
Here's one that seems to apply.
http://groups.google.com/group/micro...73b3e4db61a838

--
Tim Wilson
..NET Compact Framework MVP

"E J" <zu****@yahoo.com> wrote in message
news:OI**************@TK2MSFTNGP14.phx.gbl...
I think I am running into the same problem. I have multiple projects in
my solution and set an application setting for one of the project which
is not the start up project. This creates an entry a file called
app.config in that project. However, when I build the solution, the
solution.exe.config file does not contain the appliction setting I
created in the other project. Do I need to merge the app config files?
If so, how do I do that?

*** Sent via Developersdex http://www.developersdex.com ***

Apr 5 '06 #10
An application has but one app.config file. It is available to all code in
the application. So, yes, you need to put the settings for the non-startup
project into the app.config of the app project.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.

"E J" <zu****@yahoo.com> wrote in message
news:OI**************@TK2MSFTNGP14.phx.gbl...
I think I am running into the same problem. I have multiple projects in
my solution and set an application setting for one of the project which
is not the start up project. This creates an entry a file called
app.config in that project. However, when I build the solution, the
solution.exe.config file does not contain the appliction setting I
created in the other project. Do I need to merge the app config files?
If so, how do I do that?

*** Sent via Developersdex http://www.developersdex.com ***

Apr 5 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Robert | last post by:
I have an application with custom configuration sections in it's app.config file. Here's a shortened excerpt: <monitors> <monitor...
3
by: Charlie | last post by:
Hi: I created a config file to retrieve DSN at runtime from a C# library project (DLL). I name the file same as DLL (libRADIUS.config). Here is the contents of the file... <?xml...
1
by: Dave | last post by:
Hello. I want to create some custom settings in my Web.config file and then retrieve it in my application, exactly I want to store some connection string for my database. I'm adding these...
5
by: NoNickname | last post by:
Basically, how do I know that the release versions of all components are being published? The Build | Configuration Manager is confusing me a little in VS2005. I have three projects in my...
1
by: Nick | last post by:
Can someone please explain why? In VS2005, I created a starter kit personal website. Then used web configuration tool to setup user / roles etc (just like it says to in the welcome screen)... ...
2
by: WB | last post by:
Hi, I'm building a Windows application using Visual Studio 2005. For some reason, the Configuration Manager is missing from my Toolbar. So now in order to change my build mode (eg. Debug,...
1
by: JP.Gantlin | last post by:
I don't have the tool! What can I do? as mentioned in the web.config file: Note: As an alternative to hand editing this file you can use the web admin tool to configure settings for your...
3
by: AMP | last post by:
Hello, I asked a similar question yesterday with no responces. I want to read and write to a configuration file with user settings.(Windows App) Are there any good books, or sites that explain...
1
by: Iouri | last post by:
I have lost configuration manager in VS2005 IDE. I remember it used to be a combo box in the Tool bar where you can switch from Debug to Release mode. It is not there anymore. Any advice how to...
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:
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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.