473,671 Members | 2,382 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cracking ConfigurationMa nager

This is crazy. Does anyone have a simple example of reading a variable from
the application config file for a desktop application?

I've spent way too much time on this. I've found huge examples and lots of
help topics. But the .NET help topics are beyond poor. And that makes it
difficult for me to completely understand huge examples. And the smaller
examples I've managed to find don't work.

Since I want to get my application to do a few things in addition to reading
and writing the settings, I'd prefer to find a simple example and be able to
move on.

Has anyone out there cracked ConfigurationMa nager for a desktop app?

Thanks.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

Aug 3 '07 #1
3 2494
Smithers wrote:
2. If you want to programmaticall y write (in addition to reading), then you
have to go the more complex route presented in the links I gave earlier and
discussed below.
If you use Visual Studio 2005 you can just right-click on a project's
Properties node and select Open. Then go to the Settings tab. Just type
in you new setting's name and a default value. If you make the setting
application-copied then it cannot be written to; if you make the setting
user-scoped it can be written to easily.

VS will generate a Settings.cs file with a Settings class in it. To use
this just do this:

using <your-namespace>.Prop erties;

int maxLoops = Settings.Defaul t.MaxLoops;

// You can now use maxLoops as you would like.

Settings.Defaul t.MaxLoops = 154;
Settings.Defaul t.Save();

// You've just changed the MaxLoops setting to be 154.

This doesn't read and/or write to the <appSettingssec tion but is great
for adding user- or application-specific settings right in your class
library and/or application. But these VS-supported settings are wicked
simple to use and very flexible (say you're working on a class library,
the settings for that library can easily be copied to an app.config for
tailoring by code that uses the class library).

I decided to go through the pain of converting all my .NET 1.1 and prior
based ConfigurationSe ttings stuff to this new technique because the new
stuff didn't seem to be worth figuring out giving the VS built-in
support for the new settings. If MS does a wholesale change of the
"settings architecture" again I'm sticking with this one introduced in
..NET 2.0 - [obsolete] or not!

--
-glenn-
Aug 3 '07 #2
Thanks for pointing out something I had missed.

The Settings.cs and related VS functionality of which you speak: is it
limited to name/value pairs - or can we also store collections of related
stuff?

-"Smithers"


"G.Doten" <gd****@gmail.c omwrote in message
news:u%******** ********@TK2MSF TNGP05.phx.gbl. ..
Smithers wrote:
>2. If you want to programmaticall y write (in addition to reading), then
you have to go the more complex route presented in the links I gave
earlier and discussed below.

If you use Visual Studio 2005 you can just right-click on a project's
Properties node and select Open. Then go to the Settings tab. Just type in
you new setting's name and a default value. If you make the setting
application-copied then it cannot be written to; if you make the setting
user-scoped it can be written to easily.

VS will generate a Settings.cs file with a Settings class in it. To use
this just do this:

using <your-namespace>.Prop erties;

int maxLoops = Settings.Defaul t.MaxLoops;

// You can now use maxLoops as you would like.

Settings.Defaul t.MaxLoops = 154;
Settings.Defaul t.Save();

// You've just changed the MaxLoops setting to be 154.

This doesn't read and/or write to the <appSettingssec tion but is great
for adding user- or application-specific settings right in your class
library and/or application. But these VS-supported settings are wicked
simple to use and very flexible (say you're working on a class library,
the settings for that library can easily be copied to an app.config for
tailoring by code that uses the class library).

I decided to go through the pain of converting all my .NET 1.1 and prior
based ConfigurationSe ttings stuff to this new technique because the new
stuff didn't seem to be worth figuring out giving the VS built-in support
for the new settings. If MS does a wholesale change of the "settings
architecture" again I'm sticking with this one introduced in .NET 2.0 -
[obsolete] or not!

--
-glenn-

Aug 3 '07 #3
Smithers wrote:
The Settings.cs and related VS functionality of which you speak: is it
limited to name/value pairs - or can we also store collections of related
stuff?
You can store almost any type you want. Look in Visual Studios' Settings
tab and you'll see a type drop-down for the setting. Set it to whatever
you want. You can even browse to one of your own types.

--
-glenn-
Aug 3 '07 #4

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

Similar topics

4
7410
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 namespace name 'ConfigurationManager' does not exist in the namespace 'System.Configuration' (are you missing an assembly reference?) .
3
10725
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 practical, you define a custom key in web.config: <appSettings> <add key="ReportButtonClick" value="0" /> </appSettings>
1
12689
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 String = ConfigurationManager.ConnectionStrings(_ConnectionString).ConnectionString I get an error saying:
3
16069
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 ConfigurationManager does not recognize there is an appSettings section in the file and the last line throws an exception. It opens successfully but the collection is empty. Any thoughts as to why? Configuration configFile =
4
10972
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 normally do in VB. I'm running into various 'small' difficulties. I don't understand this: In vb, this is valid:
2
2729
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;
6
3487
by: Carl Dau | last post by:
I'm a software pirate and I think that ALL software is public domain, only idiots do pay for software, all software should be for free. But recently, copy-protection methods got better and cracking software is getting harder. So, how can I write a superb cracking program in C++ that will be able to remove any copy-protection???
3
13633
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 B's app.config. I've referenced System.configuration.dll within Project B, and from one of the classes inside Project B's namespace, I'm trying to use ConfigurationManager to write to its app.config. Unfortunately, it only finds Project A's...
0
8481
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
8400
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
8924
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
8823
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
8672
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
5702
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
4227
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
2817
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
2058
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.