Current Directory String

  • Thread starter Thread starter Brad Markisohn
  • Start date Start date
B

Brad Markisohn

I'm trying to use the Enviromnent.CurrentDirectory parameter, but it keeps
reutrning an @ in front of the string. The return format looks like:
@"C:\System\Data" and it appears that the @ is causing me problems. Can
anybody clue me into what's going on?

TIA

Brad
 
Brad said:
I'm trying to use the Enviromnent.CurrentDirectory parameter, but it keeps
reutrning an @ in front of the string. The return format looks like:
@"C:\System\Data" and it appears that the @ is causing me problems. Can
anybody clue me into what's going on?

TIA

Brad
As I understand it, the @ symbol tells the compiler that there will be
characters that usually need to be escaped in the string...

This means you can use @"C:\folder\file.txt"
instead of "c:\\folder\\file.txt"

What kind of problems are you having?
 
@ is the C# escape character, and the debugger or whatever you're using to
view the value is just indicating that the format is the logical value. So
these two strings are equivalent:

@"C:\System\Data"
"C:\\System\\Data"
 
Ben,

Thanks for the response. I'm trying to dynamically locate a directory where
data is stored. In VB.Net, I used:
strLocation = Environment.CurrentDirector & "..\data\filename.ext"
I've tried this in C#, but I'm having problems. I thought this would be a
straight forward port.

Brad
 
strLocation = Environment.CurrentDirector & "..\data\filename.ext"

string strLocation = Environment.CurrentDirector + @"..\data\filename.ext" ;
 
Typo ...

string strLocation = Environment.CurrentDirectory + @"..\data\filename.ext"
;
 
Thom,

Thanks. After more study, I found that it was the directory redirection
that was causing me problems. I wanted to be able to go up one level then
come down to a different directory as shown in my example. When I
physically remove the last directory and the separator character "\" from
the string returned from the Environment.CurrentDirectory and append the
"..\data\filename.ext" it works just fine. I'm not sure why the redirection
fails.

Brad
 
Back
Top