473,608 Members | 2,410 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

System.Configur ation.Configura tionManager.App Settings - question

Hello,

I have a config file.

<?xml version="1.0" encoding="utf-8"?>
<configuratio n>
<appSettings>
<add key="Directory" value="C:\_Data base\" />
<add key="CloseAppli cation" value="0" />
<add key="Extension" value="*.txt,*. log" />
</appSettings>
</configuration>
I read it.
string Directory;
bool CloseApplicatio n;
Directory =
System.Configur ation.Configura tionManager.App Settings["Directory"];
string help =
System.Configur ation.Configura tionManager.App Settings["CloseApplicati on"];
Int32 ret = Convert.ToInt32 ( help );
// #####// CloseApplicatio n = Convert.ToBoole an( help );
if ( ret == 0 )
CloseApplicatio n = false;
else
CloseApplicatio n = true;
A) Why can I not convert to bool? // #####// CloseApplicatio n =
Convert.ToBoole an( help );
B) All values are string in ConfigurationMa nager?
C) It is possible in the direct way boolean, double, etc?
Regards Thomas
Jan 10 '08 #1
2 3817

"Thomas Bauer" <ma******@arcor .dewrote in message
news:e3******** *************** ***********@e4g 2000hsg.googleg roups.com...
Hello,

I have a config file.

<?xml version="1.0" encoding="utf-8"?>
<configuratio n>
<appSettings>
<add key="Directory" value="C:\_Data base\" />
<add key="CloseAppli cation" value="0" />
<add key="Extension" value="*.txt,*. log" />
</appSettings>
</configuration>
I read it.
string Directory;
bool CloseApplicatio n;
Directory =
System.Configur ation.Configura tionManager.App Settings["Directory"];
string help =
System.Configur ation.Configura tionManager.App Settings["CloseApplicati on"];
Int32 ret = Convert.ToInt32 ( help );
// #####// CloseApplicatio n = Convert.ToBoole an( help );
if ( ret == 0 )
CloseApplicatio n = false;
else
CloseApplicatio n = true;
A) Why can I not convert to bool? // #####// CloseApplicatio n =
Convert.ToBoole an( help );
B) All values are string in ConfigurationMa nager?
C) It is possible in the direct way boolean, double, etc?

(Another Way to read/write configuration values)

http://geekswithblogs.net/akraus1/articles/64871.aspx

You can make it a Bool right out of the gate by using the example, and you
can call the examples by name anything you want, like ConfigData --
ConfigSettings.

And with in the Configdata.cs

[ConfigurationPr operty("closeap plication")]
public bool CloseApplicatio n {

get { return (bool)this["closeapplicati on"]; }

set{ this["closeapplicati on"] = value; }

}

Jan 10 '08 #2
Hello,
You can make it a Bool right out of the gate by using the example, and you
can call the examples by name anything you want, like ConfigData -- *
ConfigSettings.

And with in the Configdata.cs

* * * * *[ConfigurationPr operty("closeap plication")]
* * * * * * public bool CloseApplicatio n {

* * * * * * * * * get { return (bool)this["closeapplicati on"]; }

* * * * * * * * * set{ this["closeapplicati on"] = value; }

* * * * * * }
OK how?
With a assistent?

Regards Thomas

Error 1 The type "ConfigurationP roperty" is not found. (Missing using
directive or assembly relation?)

using System;
using System.Collecti ons.Generic;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows. Forms;
using System.Diagnost ics;
namespace RFileCleaner
{
public partial class frmRFileCleaner : Form
{
string Directory;
bool CloseApplicatio n;
Int32 DeleteFilesOlde rThanDays;

[ConfigurationPr operty( "CloseApplicati on" )]
public bool CloseApplicatio n2
{
get { return (bool)this["CloseApplicati on"]; }
set { this["CloseApplicati on"] = value; }
}

public frmRFileCleaner ( )
{
InitializeCompo nent();

//<add key="Directory" value="C:\_Data base\" />
//<add key="CloseAppli cation" value="0" />

Directory =
System.Configur ation.Configura tionManager.App Settings["Directory"];
string help =
System.Configur ation.Configura tionManager.App Settings["CloseApplicati on"];
Int32 ret = Convert.ToInt32 ( help );

if ( ret == 0 )
CloseApplicatio n = false;
else
CloseApplicatio n = true;

help =
System.Configur ation.Configura tionManager.App Settings["DeleteFilesOld erThanDays"];
DeleteFilesOlde rThanDays = Convert.ToInt32 ( help );

}
Jan 10 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2146
by: Sky | last post by:
Yesterday I was told that GetType(string) should not just be with a Type, but be Type, AssemblyName. Fair enough, get the reason. (Finally!). As long as it doesn't cause tech support problems down the line... What happens when my code is run on a station that only has framework 3.0 or 4.0, and this assembly, with version number defined for 2.0.0.0 , isn't available. ...breaks? Second question: Does an assembly's PublicKeyToken change...
2
7764
by: Alan T | last post by:
I have created a class library called Employee.dll and created a configuration file called Convert.config in this project. What should I use to open this config file: <?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key="employee" value="run batch file"/>
8
10208
by: Alberto | last post by:
Can you tell me how to read and modify a value in the app.config file using this class? Thank you very much
6
7524
by: Steve Kershaw | last post by:
I have a problem in which I'm trying to access a method in a .DLL from an ASP.Net web page (written in C#). I keep on getting the error "The current configuration system does not support user-scoped settings". I've done some research into this problem and I've found out that the solution has something to do with the ConfigurationManager.AppSettings for settings, or Profiles for per-user configutation in ASP.Net 2.0. However, I don't know...
3
5803
by: Jyothi Kumar | last post by:
Hi, my project is a migrated project from VS 2003 to VS 2005, in this project I used System.Configuration.ConfigurationSettings.AppSettings, now in VS 2005 it is giving a warning Message like: ConfigurationSettings.AppSettings is Obsolete, please replace with ConfigurationManager.AppSettings, but Iam unable to find this ConfigurationManager class in System.Configuration namespace, but if I add System.Configuration.dll as reference to my project...
2
2055
by: Randy Smith | last post by:
Hi ALL, I am getting this strange warning message, and I can't seem to find any solution for it. 'System.Configuration.CofigurationSettings.AppSettings is obsolete: it has been replaced by System.Configuration!System.Configuration.ConfigurationManager.AppSettings' So, does anyone have a solution to this warning message? TIA, Randy
2
5323
by: mark4asp | last post by:
In trying to get the C# conversion code for Head First Design Patterns to work I came accross a number of warnings. e.g. Warning Number: 10 Description: 'System.Configuration.ConfigurationSettings.AppSettings' is obsolete: 'This method is obsolete, it has been replaced by System.Configuration!System.Configuration.ConfigurationManager.AppSettings' E:\code\HeadFirstDesignPatternsInCSharp\Decorator.Starbuzz\Expresso.cs Line: 31
1
1791
by: =?Utf-8?B?Vmlua2k=?= | last post by:
I keep getting this warining in my code, but when i tried to look at the intellisense after system.configuration. , I couldn't find configurationManager but when i forced to put configurationManager, it gave me an errror that configurationManager does not exists. I am using .net 2.0 Warning 1 'System.Configuration.ConfigurationSettings.AppSettings' is obsolete: 'This method is obsolete, it has been replaced by...
2
2723
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 settings panel. When I try to do the following;
0
8067
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
8010
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8483
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...
0
8349
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6820
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
3967
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...
0
4030
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1607
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1336
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.