473,405 Members | 2,210 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Retrieving a File Path from the Registry in C#

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
3 5978
"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Dmitry Shaporenkov | last post by:
Hi all, I'd like to programmatically retrieve the directory of .NET framework binary tools (csc.exe, RegAsm.exe). What is the right way to do this? I can get InstallRoot via the Registry and...
5
by: David Webb | last post by:
The problem started when the Working Folder for a project was somehow set to the folder of another project. I set the correct working folder in VSS and deleted the .vbproj files that had been...
4
by: dixie | last post by:
Help, I'm really out of my depth here (not unusual I hear you say :-). I have just installed HTML Help in an application. I told it in the Project Properties the path to the help file. I then...
8
by: Steve | last post by:
Can anyone tell me the preferred method for writing and retrieving persistent information using .Net. Specifically, I am referring to information that you used to see in registry keys or .ini...
9
by: Ben Dewey | last post by:
Project: ---------------------------- I am creating a HTTPS File Transfer App using ASP.NET and C#. I am utilizing ActiveDirectory and windows security to manage the permissions. Why reinvent...
4
by: sunilj20 | last post by:
Hello, I have a requirement wherein, a user clicks on a file name in an ASP.NET web application, and the file should automatically be downloaded (Without showing the "Open", "Save As") in the...
5
by: kiran | last post by:
hi, i just wanted to retrieve path of a file residing on local client system using javascript
2
by: TwistedPair | last post by:
All, This is sort of a continuation of a previous post of mine. The code below basically reads a registry key to get a path to a folder and it watches for files created in that folder (only...
3
by: LordHog | last post by:
Hello, How would I go about finding the default handler, let's say a text file (*.txt), then launch the default handler with the file as an argument? I had found how to launch an external...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.