471,318 Members | 2,092 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,318 software developers and data experts.

How to access settings from C# in .NET 2.0?

GS
Hi,

There is reference about accessing settings file in VB.NET but nothing about
C#. How do I read settings in application settings file with C#?

Thanks,
G
Dec 22 '05 #1
6 16517
GS wrote:
Hi,

There is reference about accessing settings file in VB.NET but nothing about
C#. How do I read settings in application settings file with C#?

Thanks,
G


The same way you do it in VB.NET. The framework in language
independent, the classes are the same in both cases. All that changes
is the syntax.

Chris
Dec 22 '05 #2

GS wrote:
Hi,

There is reference about accessing settings file in VB.NET but nothing about
C#. How do I read settings in application settings file with C#?

Thanks,
G


Hi G,

When you say settings file, do you mean web.config?

If this is the case, in your code behind type
some var = System.Configuration.ConfigurationSettings.AppSett ings[index
or name of key];

Jeff

Dec 22 '05 #3

GS wrote:
Hi,

There is reference about accessing settings file in VB.NET but nothing about
C#. How do I read settings in application settings file with C#?

Thanks,
G


Hi G,

When you say settings file, do you mean web.config?

If this is the case, in your code behind type
some var = System.Configuration.ConfigurationSettings.AppSett ings[index
or name of key];

Jeff

Dec 22 '05 #4
GS
No, I meant console application. Below is part of .NET documentation about
accessing settings in VB. How do I do the same in C#?
There is no My.Settings
This section contains topics describing the My.Settings object and the tasks
it enables you to accomplish.

My.Settings
The properties of the My.Settings object provide access to your
application's settings. To add or remove settings, use the Project Designer.
For more information, see How to: Add or Remove Application Settings.

The methods of the My.Settings object allow you to save the current user
settings or revert the user settings to the last saved values.

Tasks
The following table lists examples showing how to access an application's
forms.

To See
Update the value of a user setting
How to: Change User Settings in Visual Basic

Display application and user settings in a property grid
How to: Create Property Grids for User Settings in Visual Basic

Save updated user setting values
How to: Persist User Settings in Visual Basic

Determine the values of user settings
How to: Read Application Settings in Visual Basic


"Jeff" <jb*****@dynamite.ca> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...

GS wrote:
Hi,

There is reference about accessing settings file in VB.NET but nothing
about
C#. How do I read settings in application settings file with C#?

Thanks,
G


Hi G,

When you say settings file, do you mean web.config?

If this is the case, in your code behind type
some var = System.Configuration.ConfigurationSettings.AppSett ings[index
or name of key];

Jeff

Dec 22 '05 #5
This method also works for any app.config file in a VS project. When you
compile the project, VS will create a file named "yourapp.exe.config" in the
bin directory. In the app.config place lines like the following in the
<appSettings> section:

<add key="SettingName" value ="thevalue"/>

Then in your code use

string variable =
System.Configuration.ConfigurationSettings.AppSett ings["SettingName"];

The appsettings method returns a string so you would have to convert it to
another type if you wanted to store numbers, etc.

Hope this helps.
"Jeff" wrote:

GS wrote:
Hi,

There is reference about accessing settings file in VB.NET but nothing about
C#. How do I read settings in application settings file with C#?

Thanks,
G


Hi G,

When you say settings file, do you mean web.config?

If this is the case, in your code behind type
some var = System.Configuration.ConfigurationSettings.AppSett ings[index
or name of key];

Jeff

Dec 22 '05 #6
Check out ...

YourApplicationNameSpace.Properties.Settings.Defau lt.YourSettingName

"GS" <no****@nowhere.com> wrote in message
news:eb**************@TK2MSFTNGP11.phx.gbl...
No, I meant console application. Below is part of .NET documentation about
accessing settings in VB. How do I do the same in C#?
There is no My.Settings
This section contains topics describing the My.Settings object and the
tasks it enables you to accomplish.

My.Settings
The properties of the My.Settings object provide access to your
application's settings. To add or remove settings, use the Project
Designer. For more information, see How to: Add or Remove Application
Settings.

The methods of the My.Settings object allow you to save the current user
settings or revert the user settings to the last saved values.

Tasks
The following table lists examples showing how to access an application's
forms.

To See
Update the value of a user setting
How to: Change User Settings in Visual Basic

Display application and user settings in a property grid
How to: Create Property Grids for User Settings in Visual Basic

Save updated user setting values
How to: Persist User Settings in Visual Basic

Determine the values of user settings
How to: Read Application Settings in Visual Basic


"Jeff" <jb*****@dynamite.ca> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...

GS wrote:
Hi,

There is reference about accessing settings file in VB.NET but nothing
about
C#. How do I read settings in application settings file with C#?

Thanks,
G


Hi G,

When you say settings file, do you mean web.config?

If this is the case, in your code behind type
some var = System.Configuration.ConfigurationSettings.AppSett ings[index
or name of key];

Jeff


Dec 22 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Yogesh Pancholi | last post: by
4 posts views Thread by RedHair | last post: by

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.