473,387 Members | 1,569 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,387 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 16606
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: serge calderara | last post by:
dear all, I have problem accessing section group in my configuration application file. I got an error saying thta I can have only one section ???? here is my application configuration looks...
1
by: Mike MacSween | last post by:
This looks like a bug to me. I have an expression on a report: =Format(Sum((**)*(/)),"0.00") Score is byte PercentOfGrade is double PropDegree is single ModuleCats is byte
0
by: Yogesh Pancholi | last post by:
For some unexplained reason, I am suddenly unable to browse to a virtual directory on my laptop. I have a number of sample websites to which I could happliy browse up until last week. As of Monday,...
6
by: dbuchanan | last post by:
I have a Windows Forms application that accesses SQL Server 2k from a small local network. The application has been used for weeks on other systmes but a new install on a new machine retruns...
10
by: Eric E | last post by:
Hi all, I am using an Access client linked to a PG 7.4 server via ODBC. I have a stored proc on the server that inserts rows into a table.particular table, accomplished via an INSERT within the...
2
by: Matthias Wohlmann | last post by:
Hi, I'm getting the following error when trying to start my application using Internet Explorer: "Server cannot access application directory D:\xxx. The directory does not exist or is not...
4
by: RedHair | last post by:
I developed a Win form with VS.NET 2005 + .NET 2.0 in C# There are some application settings are "User" scope and stored in xxx.settings, I can access them via Settings class and changethem with...
4
by: captainphoenix | last post by:
Windows XP Home Edition VB 2005 MS Access 2003 I am having problems importing mdb information from access to visual basic. The first application worked fine, but the second one refuses to work,...
4
by: rajshresta | last post by:
How do we access the nested class dynamically in .NET ? Basically I am using third party code (psn.disc assembly) to run few tasks and the requirement is to dynamically load the assembly at run-time....
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.