Hello,
Can somebody please tell me how I can read values from the following
configuration file. It is generated by VS 2K5 Express when I add
settings using the project properties front-end:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings"
type="System.Configuration.ApplicationSettingsGrou p, System,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="applicationsettings.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false" />
</sectionGroup>
</configSections>
<applicationSettings>
<applicationsettings.Properties.Settings>
<setting name="Test" serializeAs="String">
<value>this is a test value</value>
</setting>
</applicationsettings.Properties.Settings>
</applicationSettings>
</configuration>
The code I have:
Configuration config =
ConfigurationManager.OpenExeConfiguration(Applicat ion.ExecutablePath);
ConfigurationSection appSettings =
config.GetSection("applicationsettings.Properties. Settings");
ConfigurationSectionGroup appSettingsGroup =
config.GetSectionGroup("applicationSettings");
ConfigurationSectionCollection appSettingsSections =
appSettingsGroup.Sections;
foreach (ConfigurationSection section in appSettingsSections)
{
Console.WriteLine(section.SectionInformation.Name) ;
// stuck here, how do I get children ?
}
First of all, the code I've written seems much to complicated, just
for reading out a simple value.
Second: then what is the correct way to do it, I've read MSDN docs but
they are all based on the AppSettings section. I would like to keep
the xml intact, and read out the value of "Test" in the
"applicationSettings.Properties.Settings" section.
Since MS are saying all other methods of accessing the app.config are
rendered obsolete by the ConfigurationManager class, there must be
some way to do it.
Any help would be greatly appreciated,
Janiek Buysrogge 4 13166
Hi
I think you can use the following code snippet to access settings that
is generated by Project Designer (Project Properties )'s Setting Pane:
Properties.Settings.Default.yourSettingName
Best Regards,
A.Hadi
Hi,
Thank you for your quick answer.
You got me a step closer, I can see the name of my variable in the
intellisense list.
However, I get this error when executing the code:
A first chance exception of type
'System.Configuration.ConfigurationErrorsException ' occurred in
System.Configuration.dll
Configuration system failed to initialize
This also occurs when I put the OpenExeConfiguration before the
Properties call.
Is there any extra initialization required ?
Thanks in advance,
Janiek
On 28 Feb 2006 07:40:06 -0800, "Aboulfazl Hadi" <AH****@gmail.com>
wrote: Hi I think you can use the following code snippet to access settings that is generated by Project Designer (Project Properties )'s Setting Pane:
Properties.Settings.Default.yourSettingName
Best Regards, A.Hadi
Hi Janiek,
The biggest difference between .Net 1.1 and .Net 2.0 in terms of
Configuration is that in .Net 2.0 everything is strongly typed. For each
Configuration Section there is a specific type of class that handles it.
Your best bet is to create your own custom ConfigurationSection and
ConfigurationElement derived classes to handle your own custom Configuration
Sections.
Here's a good starting point to learn how: http://msdn2.microsoft.com/en-us/library/2tw134k3.aspx
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
A brute awe as you,
a Metallic hag entity, eat us.
"Janiek Buysrogge" <J.*********@Televic.com> wrote in message
news:55********************************@4ax.com... Hello,
Can somebody please tell me how I can read values from the following configuration file. It is generated by VS 2K5 Express when I add settings using the project properties front-end:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGrou p, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" > <section name="applicationsettings.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> </sectionGroup> </configSections> <applicationSettings> <applicationsettings.Properties.Settings> <setting name="Test" serializeAs="String"> <value>this is a test value</value> </setting> </applicationsettings.Properties.Settings> </applicationSettings> </configuration>
The code I have:
Configuration config = ConfigurationManager.OpenExeConfiguration(Applicat ion.ExecutablePath); ConfigurationSection appSettings = config.GetSection("applicationsettings.Properties. Settings"); ConfigurationSectionGroup appSettingsGroup = config.GetSectionGroup("applicationSettings"); ConfigurationSectionCollection appSettingsSections = appSettingsGroup.Sections; foreach (ConfigurationSection section in appSettingsSections) { Console.WriteLine(section.SectionInformation.Name) ;
// stuck here, how do I get children ? }
First of all, the code I've written seems much to complicated, just for reading out a simple value.
Second: then what is the correct way to do it, I've read MSDN docs but they are all based on the AppSettings section. I would like to keep the xml intact, and read out the value of "Test" in the "applicationSettings.Properties.Settings" section.
Since MS are saying all other methods of accessing the app.config are rendered obsolete by the ConfigurationManager class, there must be some way to do it.
Any help would be greatly appreciated,
Janiek Buysrogge
Seems like a lot of coding, but I'll try it out.
Thanks
On Tue, 28 Feb 2006 13:20:27 -0500, "Kevin Spencer"
<ke***@DIESPAMMERSDIEtakempis.com> wrote: Hi Janiek,
The biggest difference between .Net 1.1 and .Net 2.0 in terms of Configuration is that in .Net 2.0 everything is strongly typed. For each Configuration Section there is a specific type of class that handles it. Your best bet is to create your own custom ConfigurationSection and ConfigurationElement derived classes to handle your own custom Configuration Sections.
Here's a good starting point to learn how:
http://msdn2.microsoft.com/en-us/library/2tw134k3.aspx This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Michael Debus |
last post by:
Hi, I try to read a value from app.config file using this code:
string
s=System.Configuration.ConfigurationManager.AppSettings.ToString();
I got the compiler error:
Error 1 The type or...
|
by: Myo Zaw |
last post by:
hi,
can i use configurationmanager in .net 2.0 windows form. cause i have
an app.config file and i couldn't extract the data from there by using
configurationmanager nor 1.1 feature. do u have any...
|
by: robertino |
last post by:
Hi All,
(VS 2005 Pro, Win XP Pro)
I'm trying to read some app settings from my app.config file (normal
Win app), have included the System.Configuration namespace in my app,
but when I try to...
|
by: natasha |
last post by:
Hello everybody,
you can use ConfigurationManager.AppSettings.Set method
(ConfigurationManager is in System.Web.Configuration namespace) to store a
modified value from web.config.
To be...
|
by: shapper |
last post by:
Hello,
I create a few VB classes under app_code of a web site.
Now I am trying to create a library project.
Something strange is going on. I have the following line:
Dim connectionString As...
| |
by: Mark |
last post by:
I am trying to read the appsettings section of a configuration file
using the ConfigurationManager object (ASP.NET application) with the
following three lines but for some reason the...
|
by: Jim in Arizona |
last post by:
I've been using VB 2005 for a few years now. My entire coding history is
VB related.
This weekend I decided to start learning C#. I'm at work now and decided
to do some coding in C# that I would...
|
by: remya1000 |
last post by:
i'm using VB.NET 2003.
Last time while i did a program in Vb.Net 2005, i use "Configuration". and i could read and write to that XML configuration file like the example below.
CODES:...
|
by: pantagruel |
last post by:
Hi,
I have a Visual studio 2005 project that runs as a Windows Service. In
it I have declared that I am using System.Configuration.
I have set one application setting for the service using the...
|
by: Jeff |
last post by:
I have a solution with two projects. Project A is the startup
project, while Project B serves as the project with the data logic.
At run time, the first thing I need to do is write to Project...
|
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,...
| |
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...
|
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: 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...
|
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...
|
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...
|
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...
| |
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 ...
|
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...
| |