Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / January 2008

Tip: Looking for answers? Try searching our database.

System.Configuration.ConfigurationManager.AppSettings - question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Thomas Bauer - 10 Jan 2008 05:30 GMT
Hello,

I have a config  file.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
 <appSettings>
   <add key="Directory" value="C:\_Database\" />
   <add key="CloseApplication" value="0" />
   <add key="Extension" value="*.txt,*.log" />
 </appSettings>
</configuration>

I read it.

string Directory;
   bool   CloseApplication;

 Directory =
System.Configuration.ConfigurationManager.AppSettings["Directory"];
     string help =
System.Configuration.ConfigurationManager.AppSettings["CloseApplication"];
     Int32 ret = Convert.ToInt32( help );
//  #####//    CloseApplication = Convert.ToBoolean( help );

     if ( ret == 0 )
       CloseApplication = false;
     else
       CloseApplication = true;

A) Why can I not convert to bool?  //  #####//    CloseApplication =
Convert.ToBoolean( help );
B) All values are string in ConfigurationManager?
C) It is possible in the direct way boolean, double, etc?

Regards Thomas
Mr. Arnold - 10 Jan 2008 06:17 GMT
> Hello,
>
[quoted text clipped - 30 lines]
> B) All values are string in ConfigurationManager?
> 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

        [ConfigurationProperty("closeapplication")]
           public bool CloseApplication {

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

                 set{ this["closeapplication"] = value; }

           }
Thomas Bauer - 10 Jan 2008 07:29 GMT
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 --  
[quoted text clipped - 10 lines]
>
>             }
OK how?
With a assistent?

Regards Thomas

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

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
namespace RFileCleaner
{
 public partial class frmRFileCleaner : Form
 {
   string Directory;
   bool   CloseApplication;
   Int32  DeleteFilesOlderThanDays;

   [ConfigurationProperty( "CloseApplication" )]
   public bool CloseApplication2
   {
     get { return (bool)this["CloseApplication"]; }
     set { this["CloseApplication"] = value; }
   }

   public frmRFileCleaner( )
   {
     InitializeComponent();

     //<add key="Directory" value="C:\_Database\" />
     //<add key="CloseApplication" value="0" />

     Directory =
System.Configuration.ConfigurationManager.AppSettings["Directory"];
     string help =
System.Configuration.ConfigurationManager.AppSettings["CloseApplication"];
     Int32 ret = Convert.ToInt32( help );

     if ( ret == 0 )
       CloseApplication = false;
     else
       CloseApplication = true;

     help =
System.Configuration.ConfigurationManager.AppSettings["DeleteFilesOlderThanDays"];
     DeleteFilesOlderThanDays = Convert.ToInt32( help );

   }

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.