Click here to Skip to main content
14,603,335 members
   

C#

 
GeneralRe: HttpResponse Compression... ? Pin
Trapper-Hell10-Jun-09 6:25
MemberTrapper-Hell10-Jun-09 6:25 
GeneralRe: HttpResponse Compression... ? Pin
saurabh sahay10-Jun-09 6:35
Membersaurabh sahay10-Jun-09 6:35 
QuestionExtracting Repeating Table Data In a Web Part Pin
lday8610-Jun-09 5:42
Memberlday8610-Jun-09 5:42 
Questionchanging the color and text of the label control dynamically from the retrieved values from the database Pin
praveenkumar_vittaboina10-Jun-09 4:58
Memberpraveenkumar_vittaboina10-Jun-09 4:58 
AnswerRe: changing the color and text of the label control dynamically from the retrieved values from the database Pin
Tom Deketelaere10-Jun-09 5:22
professionalTom Deketelaere10-Jun-09 5:22 
Questioncrystal reports problem after installing the application. Pin
praveenkumar_vittaboina10-Jun-09 4:57
Memberpraveenkumar_vittaboina10-Jun-09 4:57 
AnswerRe: crystal reports problem after installing the application. Pin
Tom Deketelaere10-Jun-09 5:19
professionalTom Deketelaere10-Jun-09 5:19 
QuestionChecking a registry key exists Pin
Martin3108810-Jun-09 4:21
MemberMartin3108810-Jun-09 4:21 
Hi everyone,

I'm writing a little application and I've hit a bit of a problem.

part of the program uses the registry to store certain things. I have no problem writing or reading a key. But I need to be able to check the key exists, if it does do this, if not write the key.

Here's the code I'm currently using:

using Microsoft.Win32;<br />
RegistryKey MyRegKey = Registry.LocalMachine.OpenSubKey("software\\MyApp\\SaveData");<br />
            if (MyRegKey != null)<br />
            {<br />
                string OptCurrency = MyRegKey .GetValue("Currency").ToString();<br />
            }<br />
            else<br />
            {<br />
                RegistryKey CreateMyRegKey = Registry.LocalMachine.CreateSubKey("software\\MyApp\\SaveData");<br />
                CreateMyRegKey .SetValue("Currency", 0);<br />
                string OptCurrency = "0";<br />
            }<br />
MyRegKey.Close();


This is fine if the key exists, but doesn't recognise if it does not, and runs through the if rather than the else.

Any help would be greatly appreciated
Many thanks
Martin
AnswerRe: Checking a registry key exists Pin
Henry Minute10-Jun-09 4:45
MemberHenry Minute10-Jun-09 4:45 
GeneralRe: Checking a registry key exists Pin
Martin3108810-Jun-09 4:57
MemberMartin3108810-Jun-09 4:57 
GeneralRe: Checking a registry key exists Pin
Henry Minute10-Jun-09 5:07
MemberHenry Minute10-Jun-09 5:07 
GeneralRe: Checking a registry key exists Pin
Martin3108810-Jun-09 5:35
MemberMartin3108810-Jun-09 5:35 
GeneralRe: Checking a registry key exists Pin
Henry Minute10-Jun-09 6:16
MemberHenry Minute10-Jun-09 6:16 
GeneralRe: Checking a registry key exists Pin
Martin3108810-Jun-09 6:28
MemberMartin3108810-Jun-09 6:28 
GeneralRe: Checking a registry key exists Pin
Martin3108810-Jun-09 23:57
MemberMartin3108810-Jun-09 23:57 
Questioncheckedlistbox - save checked items for future run Pin
havejeet10-Jun-09 3:50
Memberhavejeet10-Jun-09 3:50 
AnswerRe: checkedlistbox - save checked items for future run Pin
Manas Bhardwaj10-Jun-09 3:51
professionalManas Bhardwaj10-Jun-09 3:51 
AnswerRe: checkedlistbox - save checked items for future run Pin
Rajesh R Subramanian10-Jun-09 4:01
professionalRajesh R Subramanian10-Jun-09 4:01 
Questiontaking null instead of value Pin
KIDYA10-Jun-09 3:01
MemberKIDYA10-Jun-09 3:01 
AnswerRe: taking null instead of value Pin
Tom Deketelaere10-Jun-09 3:05
professionalTom Deketelaere10-Jun-09 3:05 
AnswerRe: taking null instead of value Pin
Colin Angus Mackay10-Jun-09 5:04
MemberColin Angus Mackay10-Jun-09 5:04 
GeneralRe: taking null instead of value Pin
KIDYA11-Jun-09 18:35
MemberKIDYA11-Jun-09 18:35 
QuestionSQL Database is not saved after data inserted!! Pin
Zohair8310-Jun-09 2:25
MemberZohair8310-Jun-09 2:25 
AnswerRe: SQL Database is not saved after data inserted!! Pin
EliottA10-Jun-09 2:57
MemberEliottA10-Jun-09 2:57 
GeneralRe: SQL Database is not saved after data inserted!! Pin
Zohair8310-Jun-09 3:26
MemberZohair8310-Jun-09 3:26 

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.