Click here to Skip to main content
15,893,668 members
Home / Discussions / C#
   

C#

 
GeneralRe: IE Toolband Pin
Anonymous20-Sep-04 11:06
Anonymous20-Sep-04 11:06 
QuestionBittorrent client in C#? Pin
Marlun20-Sep-04 9:08
Marlun20-Sep-04 9:08 
AnswerRe: Bittorrent client in C#? Pin
Steven Campbell20-Sep-04 10:30
Steven Campbell20-Sep-04 10:30 
GeneralRe: Bittorrent client in C#? Pin
Marlun21-Sep-04 19:32
Marlun21-Sep-04 19:32 
GeneralDataGrid Sorting Problem using a DataSet from ViewState Pin
veroBT20-Sep-04 7:37
veroBT20-Sep-04 7:37 
GeneralRe: DataGrid Sorting Problem using a DataSet from ViewState Pin
Heath Stewart20-Sep-04 13:54
protectorHeath Stewart20-Sep-04 13:54 
GeneralC# and org.apache.log4j.PropertyConfigurator Pin
devvvy20-Sep-04 4:22
devvvy20-Sep-04 4:22 
GeneralRe: C# and org.apache.log4j.PropertyConfigurator Pin
Heath Stewart20-Sep-04 6:46
protectorHeath Stewart20-Sep-04 6:46 
There's already a configuration framework in place for the .NET Framework. Read about the IConfigurationSectionHandler interface at http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemConfigurationIConfigurationSectionHandlerClassTopic.asp[^], as well as many configuration section handlers that are already implemented like NameValueSectionHandler[^] and others listed as implementations on the documentation for IConfigurationSectionHandler. Using this framework for configuration files unifies configuration - from runtime settings to application settings - for .NET applications.

To read more about how configuration files work in .NET as well as how to implement your own sections, read Configuring Applications[^] in the .NET Framework.

So, if you wanted a key/value pair configuration section, you could reuse the NameValueSectionHandler like so:
<configuration>
  <configSections>
    <section name="mysettings"
      type="System.Configuration.NameValueSectionHandler, System" />
  </configSections>
  <mysettings>
    <add key="opt1" value="myvalue" />
    <add key="opt2" value="somevalue" />
  </mysettings>
</configuration>
To use this in your code:
using System;
using System.Configuration;
 
class Test
{
  static void Main()
  {
    NameValueCollection settings = ConfigurationSettings.GetConfig("mysettings");
    foreach (DictionaryEntry setting in settings)
      Console.WriteLine("{0} = {1}", setting.Key, setting.Value);
  }
}
It's important that your configuration file match the executable name for your Windows Forms application or Windows Service (i.e., if your .EXE is named myapp.exe, then you're .config file is named myapp.exe.config) and be located in the same directory as your .EXE (this means that libraries - .dlls - use settings from the .exe that loads them), or use Web.config for ASP.NET applications and be located in the virtual host root (/), in the web application's root (/myapp, for example, which inherit settings from the virtual host's root Web.config), or in a sub-directory of your application (also named Web.config, but can only override some sections like <authorization>.

All .config files inherit settings from machine.config that is in the config sub-directory of your Framework installation for whichever version the application has loaded (or is loaded into).

You can find more about this from the link above.

This posting is provided "AS IS" with no warranties, and confers no rights.

Software Design Engineer
Developer Division Sustained Engineering
Microsoft

[My Articles]
GeneralRe: C# and org.apache.log4j.PropertyConfigurator Pin
Steven Campbell20-Sep-04 7:06
Steven Campbell20-Sep-04 7:06 
GeneralRe: C# and org.apache.log4j.PropertyConfigurator Pin
Heath Stewart20-Sep-04 7:11
protectorHeath Stewart20-Sep-04 7:11 
GeneralRe: C# and org.apache.log4j.PropertyConfigurator Pin
devvvy21-Sep-04 7:53
devvvy21-Sep-04 7:53 
GeneralRe: C# and org.apache.log4j.PropertyConfigurator Pin
devvvy21-Sep-04 7:52
devvvy21-Sep-04 7:52 
GeneralRe: C# and org.apache.log4j.PropertyConfigurator Pin
Heath Stewart21-Sep-04 11:01
protectorHeath Stewart21-Sep-04 11:01 
GeneralRe: C# and org.apache.log4j.PropertyConfigurator Pin
devvvy22-Sep-04 17:26
devvvy22-Sep-04 17:26 
GeneralRe: C# and org.apache.log4j.PropertyConfigurator Pin
Heath Stewart22-Sep-04 20:21
protectorHeath Stewart22-Sep-04 20:21 
GeneralRe: C# and org.apache.log4j.PropertyConfigurator Pin
devvvy22-Sep-04 20:39
devvvy22-Sep-04 20:39 
GeneralRelating datagrid rows to datatable rows Pin
blakeb_120-Sep-04 4:07
blakeb_120-Sep-04 4:07 
GeneralRe: Relating datagrid rows to datatable rows Pin
Anonymous20-Sep-04 8:24
Anonymous20-Sep-04 8:24 
GeneralCrystal Reports progress in an app Pin
Mr. Labenche20-Sep-04 4:04
Mr. Labenche20-Sep-04 4:04 
GeneralRe: Crystal Reports progress in an app Pin
Dave Kreskowiak20-Sep-04 6:44
mveDave Kreskowiak20-Sep-04 6:44 
GeneralRe: Crystal Reports progress in an app Pin
Mr. Labenche23-Sep-04 1:24
Mr. Labenche23-Sep-04 1:24 
GeneralSearch and display text in richtextbox Pin
clatten20-Sep-04 3:24
clatten20-Sep-04 3:24 
GeneralRe: Search and display text in richtextbox Pin
mav.northwind20-Sep-04 3:48
mav.northwind20-Sep-04 3:48 
GeneralRe: Search and display text in richtextbox Pin
clatten20-Sep-04 5:14
clatten20-Sep-04 5:14 
GeneralCrystal Reports progress in an app Pin
Mr. Labenche20-Sep-04 2:58
Mr. Labenche20-Sep-04 2:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.