Retrieving a File Path from the Registry in C#

B

Blake McNeill

How do you retrieve a file path which was stored in the Registry as a string
without ending up with a string which has all the slashes escaped which make
it useless for file IO? I can see the file path in the registry using
RegEdit and it is exactly what I want, but when I use:

string filePath = Registry.GetValue(keyPath, keyName, null).ToString();

filePath is something like C:\\Data\\MyFile.txt when I need it to be
C:\Data\MyFile.txt, what am I missing?

Thanks
Blake
 
B

Barry Kelly

Blake McNeill said:
How do you retrieve a file path which was stored in the Registry as a string
without ending up with a string which has all the slashes escaped which make
it useless for file IO? I can see the file path in the registry using
RegEdit and it is exactly what I want, but when I use:

string filePath = Registry.GetValue(keyPath, keyName, null).ToString();

filePath is something like C:\\Data\\MyFile.txt when I need it to be
C:\Data\MyFile.txt, what am I missing?

1) The debugger is showing the string with the slashes, I think. Print
the value to the console and you should see that it is in fact correct.

2) Even if there were in fact two slashes, it wouldn't matter - Windows
will remove the extra slashes automatically.

-- Barry
 
B

Blake McNeill

You are correct, my bad, the problem was the object (or lack thereof) that I
was using to load the file into. A 4:00am coding error I guess.

Thanks
Blake
 
V

Vadym Stetsyak

Hello, Blake!

BM> string filePath = Registry.GetValue(keyPath, keyName, null).ToString();

BM> filePath is something like C:\\Data\\MyFile.txt when I need it to be
BM> C:\Data\MyFile.txt, what am I missing?

Nothing ::cool: You can use that path in file I/O.

Slash must be escaped in order to mean "slash", because if you have \nuke, then it will mean 'line feed'uke, unescaped slash gives another meaning to the symbol that follows it.


--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top