Re: @ symbol in C#
Check my post under Willy. That might help you.
"Christof Nordiek" wrote:
Check my post under Willy. That might help you.
"Christof Nordiek" wrote:
Hi, SAL
>
which statement actually is throwing the Exception?
>
It has to be either File.Exists(str FileName)
or ProcessFile(str FileName).
The last is a Method of your class, so it has to be another statement in
there.
>
>
"SAL" <SAL@discussion s.microsoft.com schrieb im Newsbeitrag
news:A768C5F5-1C5C-43B0-BEC8-3D607A3CB257@mi crosoft.com...
>
>
>
>
which statement actually is throwing the Exception?
>
It has to be either File.Exists(str FileName)
or ProcessFile(str FileName).
The last is a Method of your class, so it has to be another statement in
there.
>
>
"SAL" <SAL@discussion s.microsoft.com schrieb im Newsbeitrag
news:A768C5F5-1C5C-43B0-BEC8-3D607A3CB257@mi crosoft.com...
Here is the code I am using:
string strSourceDirect ory="C:\\Docume nts and Settings\\admin \\My
Documents\\Exce l\\Excel\\";
string [] strarrDirectory Names=
Directory.GetDi rectories(strSo urceDirectory);
string [] strarrFileNames = Directory.GetFi les(strSourceDi rectory);
foreach(string strFileName in strarrFileNames )
{
if(Directory.Ex ists(strSourceD irectory))
{
// This path is a directory
if(File.Exists( strFileName))
{
// This path is a file
ProcessFile(str FileName);
}
else
{
// No File Found
}
}
else
{
// No such directory
}
}// End foreach(string strFileName in strarrFileNames )
I've tried declare the string both ways, with @ and with out and the value
is always the same @"C:\Documen ts and Settings\admin\ My
Documents\Excel \Excel\"
As for the Permissions, I have Admin rights to my box, so I have access to
this directory. Just for simplicity if I declare string
strSourceDirect ory="C:\\temp\\ somedirectory\\ ";, it still gives me the
value
@"C:\temp\somed irectory\"
"Chris Dunaway" wrote:
string strSourceDirect ory="C:\\Docume nts and Settings\\admin \\My
Documents\\Exce l\\Excel\\";
string [] strarrDirectory Names=
Directory.GetDi rectories(strSo urceDirectory);
string [] strarrFileNames = Directory.GetFi les(strSourceDi rectory);
foreach(string strFileName in strarrFileNames )
{
if(Directory.Ex ists(strSourceD irectory))
{
// This path is a directory
if(File.Exists( strFileName))
{
// This path is a file
ProcessFile(str FileName);
}
else
{
// No File Found
}
}
else
{
// No such directory
}
}// End foreach(string strFileName in strarrFileNames )
I've tried declare the string both ways, with @ and with out and the value
is always the same @"C:\Documen ts and Settings\admin\ My
Documents\Excel \Excel\"
As for the Permissions, I have Admin rights to my box, so I have access to
this directory. Just for simplicity if I declare string
strSourceDirect ory="C:\\temp\\ somedirectory\\ ";, it still gives me the
value
@"C:\temp\somed irectory\"
"Chris Dunaway" wrote:
SAL wrote:
Hi Jon,
Eventually, the directory path will be read from a database table
instead of
hard-coding in my program, but for now while I'm testing I have it
declared
this way. I did a cut-n-paste from the address line in Windows
Explorer to
make sure I had the path correct, but C# is implicitly putting the @
symbol
in front of the path causing errors.
>
Notice that the @ symbol is *outside* of the quotation marks and is not
part of the string. In C# the @ symbol means that you don't have to
escape the slashes in a string. For example, the following lines are
equivalent:
>
string s = "c:\\Progra m Files\\Blah";
>
string s = @"c:\Program Files\Blah";
>
Can you show us the code where you're using the string?
>
>
>
>
"Jon Skeet [C# MVP]" wrote:
SAL wrote:
I do not have any trouble declaring string values except when it
comes to
directory path's. Why does C# implicitly put a @ symbol at the
being of a
String value that has been declared like this:
string strSourceDirect ory="C:\\Docume nts and Settings\\admin \\My
Documents\\Exce l\\Excel\\";
The value that strSourceDirect ory gets assigned is:
@"C:\Documen ts and Settings\admin\ My Documents\Excel \Excel\"
>
C# isn't doing that at all. It's just what the debugger is showing
you.
The two strings above are the same.
>
How do I get around this because my program errors out, because the
directory path in strSourceDirect ory that I am assigning to a
specific
document I want to open does not exist?
>
Then the directory doesn't exist - it's nothing to do with the
backslashes.
>
Did you *mean* to have Excel in there twice, by the way?
>
Jon
>
>
>
>
Hi Jon,
Eventually, the directory path will be read from a database table
instead of
hard-coding in my program, but for now while I'm testing I have it
declared
this way. I did a cut-n-paste from the address line in Windows
Explorer to
make sure I had the path correct, but C# is implicitly putting the @
symbol
in front of the path causing errors.
>
Notice that the @ symbol is *outside* of the quotation marks and is not
part of the string. In C# the @ symbol means that you don't have to
escape the slashes in a string. For example, the following lines are
equivalent:
>
string s = "c:\\Progra m Files\\Blah";
>
string s = @"c:\Program Files\Blah";
>
Can you show us the code where you're using the string?
>
>
>
>
"Jon Skeet [C# MVP]" wrote:
SAL wrote:
I do not have any trouble declaring string values except when it
comes to
directory path's. Why does C# implicitly put a @ symbol at the
being of a
String value that has been declared like this:
string strSourceDirect ory="C:\\Docume nts and Settings\\admin \\My
Documents\\Exce l\\Excel\\";
The value that strSourceDirect ory gets assigned is:
@"C:\Documen ts and Settings\admin\ My Documents\Excel \Excel\"
>
C# isn't doing that at all. It's just what the debugger is showing
you.
The two strings above are the same.
>
How do I get around this because my program errors out, because the
directory path in strSourceDirect ory that I am assigning to a
specific
document I want to open does not exist?
>
Then the directory doesn't exist - it's nothing to do with the
backslashes.
>
Did you *mean* to have Excel in there twice, by the way?
>
Jon
>
>
>
>
>
>
Comment