473,791 Members | 2,947 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 16627
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
2770
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
15478
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
1783
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 honestly have not changed anything at all. I have checked and re-checked that ASPNET indeed has...
6
2573
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 ver. 1.0.3705 is installed Dot Net Framework ver. 1.1.4322 is installed
10
3572
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 modify these records via table or form view, giving its generic "Write conflict: another user has...
2
3102
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 Integrated Windows authentication. In the web.config i have set impersonation="true" userName="test"....
4
3596
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 default setting?
4
1395
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 defined. C:\Documents and Settings\msennel1\Desktop\hw6\Airline...
4
1302
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
9666
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10419
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10201
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10147
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9023
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6770
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5424
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4100
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
2
3709
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.