By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,975 Members | 1,091 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,975 IT Pros & Developers. It's quick & easy.

Retrieving a File Path from the Registry in C#

P: n/a
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
May 16 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"Blake McNeill" <De****@SonicLogger.com> wrote:
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
May 16 '06 #2

P: n/a
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

"Barry Kelly" <ba***********@gmail.com> wrote in message
news:nd********************************@4ax.com...
"Blake McNeill" <De****@SonicLogger.com> wrote:
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

May 16 '06 #3

P: n/a
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
May 16 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.