Retrieving a File Path from the Registry in C#

  • Thread starter Thread starter Blake McNeill
  • Start date Start date
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
 
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
 
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
 
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 :8-) 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
 
Back
Top