473,574 Members | 2,668 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 16619
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.Configur ation.Configura tionSettings.Ap pSettings[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.Configur ation.Configura tionSettings.Ap pSettings[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*****@dynami te.ca> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.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.Configur ation.Configura tionSettings.Ap pSettings[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.co nfig" in the
bin directory. In the app.config place lines like the following in the
<appSettings> section:

<add key="SettingNam e" value ="thevalue"/>

Then in your code use

string variable =
System.Configur ation.Configura tionSettings.Ap pSettings["SettingNam e"];

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.Configur ation.Configura tionSettings.Ap pSettings[index
or name of key];

Jeff

Dec 22 '05 #6
Check out ...

YourApplication NameSpace.Prope rties.Settings. Default.YourSet tingName

"GS" <no****@nowhere .com> wrote in message
news:eb******** ******@TK2MSFTN GP11.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*****@dynami te.ca> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.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.Configur ation.Configura tionSettings.Ap pSettings[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
2748
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 like: ================================================ <?xml version="1.0" encoding="utf-8" ?>
1
15466
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
1764
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, if I browse to any of the sites, I get an HttpException saying "The directory does not exist or is not accessible because of security settings." I...
6
2558
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 errors. The machine is a new laptop Windows XP Pro SP2 The machine is up to date with respect to the dot net framework. Details: Dot Net Framework...
10
3544
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 body of the stored proc. The procedure does not explicitly commit this data, as no transactions are invoked. The problem is that Access will not...
2
3086
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 accessible because of security settings." In IIS I have set Directory Security for my application to allow Anonymous access (using IUSR_<Server>) and...
4
3583
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 Settings.Save(); However, if I change and save them then my app will read the change from the user.config , my question is how to access the original...
4
1368
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, giving me a list of build errors pertaining to " not defined..." see below Error 1 Type 'AirlineReservationForm.Sennello_06DataSet' is not...
4
1292
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. Here is the code snippet: namespace psn.disc { public class discexec { public int name; public discsettings settings;
0
7736
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8249
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8106
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6461
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5305
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3743
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2251
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1350
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1066
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.