Click here to Skip to main content
15,897,184 members
Articles / Programming Languages / C#
Article

Registry Wrapper to save your Application settings

Rate me:
Please Sign up or sign in to vote.
3.17/5 (6 votes)
6 Apr 2005CPOL 40.6K   335   16   5
This article describes a Registry wrapper to save your application settings like recent files information.

Introduction

This article describes a Registry wrapper to save your application settings like recent files information.

Using the code

1. Save your application setting

This will save your setting at HKEY_CURRENT_USER\Software:

C#
MyReg reg=new MyReg("AppName");  //Change AppName with your application name
reg["setting1"]=1;
reg[@"setting1\setting1"]="2";
reg[@"setting1\setting1\setting1"]="3";

2. Retrieve your application setting

C#
MessageBox.Show(reg["setting1"].ToString());
MessageBox.Show(reg[@"setting1\setting1"].ToString());
MessageBox.Show(reg[@"setting1\setting1\setting1"].ToString());

3. Delete your setting

C#
reg.Delete();

4. Save recent files

Add your recent files in an ArrayList.

C#
ArrayList list=new ArrayList();
list.Add(@"c:\file1.txt");
list.Add(@"c:\file2.txt");
reg.RecentFiles=list;
list.Clear();
list=reg.RecentFiles;
MessageBox.Show(list[1].ToString());

5. Save file extension opener

To open file *.abc with your application, use the code below:

C#
reg.SaveOpenWith("abc", "myApplication", 
               @"c:\Project\Vc7\Km\Debug\Km.exe");

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
CEO Odihost
Indonesia Indonesia
Learned programming since elementry school with QBASIC. Until now have learned a bit about VB, java, html, php, asp, delphi. He is taking his master degree in finance. Currently working for a great company(desain web), and stock trading. Own various website about option strategy, lose weight, and Invest Money.

Comments and Discussions

 
GeneralThank you Pin
korrawit14-Nov-07 22:17
korrawit14-Nov-07 22:17 
GeneralTypical "China-code" (nothing personal) Pin
lastochkin2-Oct-07 3:59
lastochkin2-Oct-07 3:59 
Pretty sample: continuous "copy'n'paste"s flavoured with "try/catch{}"s for error diagnostics preventing. Shame!


//\ Las!

GeneralThanks for the article, I like it. Pin
spinoza12-Oct-06 3:12
spinoza12-Oct-06 3:12 
GeneralXML configuration files Pin
Daniel Fisher (lennybacon)13-Apr-05 1:33
Daniel Fisher (lennybacon)13-Apr-05 1:33 
AnswerRe: XML configuration files Pin
RGabo1-Sep-05 15:38
RGabo1-Sep-05 15:38 

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.