strange c# - vb difference

  • Thread starter Thread starter Tina
  • Start date Start date
T

Tina

I'm using 1.1/vs.net 2003 ...

C#example..............

string myPath = Server.MapPath(".\\Data\\" + (string)
Session["LogoFileName"]);

Produces this value in myPath

?myPath
@"c:\inetpub\wwwroot\CSharpCustomers\Data\GaryRocks.jpg"



VB example.............

Dim myPath As String = Server.MapPath(".\Data\" + Session("LogoFileName"))

?myPath
"C:\Inetpub\wwwroot\CPCustomers\Data\GaryRocks.jpg"

the vb example works. the c# does not work. I notice that @ preceding the
string in the c# example. Could that be the difference? What am I doing
wrong in the C# example?

thanks,
T
 
Tina said:
I'm using 1.1/vs.net 2003 ...

C#example..............

string myPath = Server.MapPath(".\\Data\\" + (string)
Session["LogoFileName"]);

Produces this value in myPath

?myPath
@"c:\inetpub\wwwroot\CSharpCustomers\Data\GaryRocks.jpg"



VB example.............

Dim myPath As String = Server.MapPath(".\Data\" + Session("LogoFileName"))

?myPath
"C:\Inetpub\wwwroot\CPCustomers\Data\GaryRocks.jpg"

the vb example works. the c# does not work. I notice that @ preceding
the string in the c# example. Could that be the difference? What am I
doing wrong in the C# example?

The only difference I see here is CSharpCustomers vs. CPCustomers, which I
hope is a typing error on your part, or else it makes no sense at all.

In C#, the @ means that backslashes in the string are not to be given
special interpretation.

So @"\" and "\\" in C# are both the same as "\" in Basic.
 
The backward slash (\) character can be used in a format string to turn off
the special meaning of
the character that follows it. For example, "\{" will cause a literal "{" to
be displayed, and "\\" will
display a literal "\". The at sign (@) character can be used to represent an
entire string verbatim. For
example, @"\\server\share" will be processed as \\server\share.

chanmm
 
I'm coverting a vb project to a c# project so those are the names of the two
projects.

Thanks for telling me what the @ means. Your explanation tells me the two
strings are identical (albiet the diff in project names). My mystery
remains as to why the c# version cannot find the jpg.
T


Michael A. Covington said:
Tina said:
I'm using 1.1/vs.net 2003 ...

C#example..............

string myPath = Server.MapPath(".\\Data\\" + (string)
Session["LogoFileName"]);

Produces this value in myPath

?myPath
@"c:\inetpub\wwwroot\CSharpCustomers\Data\GaryRocks.jpg"



VB example.............

Dim myPath As String = Server.MapPath(".\Data\" +
Session("LogoFileName"))

?myPath
"C:\Inetpub\wwwroot\CPCustomers\Data\GaryRocks.jpg"

the vb example works. the c# does not work. I notice that @ preceding
the string in the c# example. Could that be the difference? What am I
doing wrong in the C# example?

The only difference I see here is CSharpCustomers vs. CPCustomers, which I
hope is a typing error on your part, or else it makes no sense at all.

In C#, the @ means that backslashes in the string are not to be given
special interpretation.

So @"\" and "\\" in C# are both the same as "\" in Basic.
 
Yes, I know that. That's why I put the extra back slashes in the c#
version. Have you any idea why the C# version canot find the jpg?
T

chanmm said:
The backward slash (\) character can be used in a format string to turn
off the special meaning of
the character that follows it. For example, "\{" will cause a literal "{"
to be displayed, and "\\" will
display a literal "\". The at sign (@) character can be used to represent
an entire string verbatim. For
example, @"\\server\share" will be processed as \\server\share.

chanmm


Tina said:
I'm using 1.1/vs.net 2003 ...

C#example..............

string myPath = Server.MapPath(".\\Data\\" + (string)
Session["LogoFileName"]);

Produces this value in myPath

?myPath
@"c:\inetpub\wwwroot\CSharpCustomers\Data\GaryRocks.jpg"



VB example.............

Dim myPath As String = Server.MapPath(".\Data\" +
Session("LogoFileName"))

?myPath
"C:\Inetpub\wwwroot\CPCustomers\Data\GaryRocks.jpg"

the vb example works. the c# does not work. I notice that @ preceding
the string in the c# example. Could that be the difference? What am I
doing wrong in the C# example?

thanks,
T
 
I have no idea why it cannot find the jpg. You are sure the jpg is in
BOTH folders?
 
At the risk of pointing the obvious (which might not help anyway)...is your
VB project located in the same folder as your C# folder? The path returned by
MapPath will return the path under which it is run and the image must be
located in the data folder under that.

Tina said:
Yes, I know that. That's why I put the extra back slashes in the c#
version. Have you any idea why the C# version canot find the jpg?
T

chanmm said:
The backward slash (\) character can be used in a format string to turn
off the special meaning of
the character that follows it. For example, "\{" will cause a literal "{"
to be displayed, and "\\" will
display a literal "\". The at sign (@) character can be used to represent
an entire string verbatim. For
example, @"\\server\share" will be processed as \\server\share.

chanmm


Tina said:
I'm using 1.1/vs.net 2003 ...

C#example..............

string myPath = Server.MapPath(".\\Data\\" + (string)
Session["LogoFileName"]);

Produces this value in myPath

?myPath
@"c:\inetpub\wwwroot\CSharpCustomers\Data\GaryRocks.jpg"



VB example.............

Dim myPath As String = Server.MapPath(".\Data\" +
Session("LogoFileName"))

?myPath
"C:\Inetpub\wwwroot\CPCustomers\Data\GaryRocks.jpg"

the vb example works. the c# does not work. I notice that @ preceding
the string in the c# example. Could that be the difference? What am I
doing wrong in the C# example?

thanks,
T
 
no. I found the problem to be something else and reposted "A strange c# -
vb difference"
sorry
T
Mike Collins said:
At the risk of pointing the obvious (which might not help anyway)...is
your
VB project located in the same folder as your C# folder? The path returned
by
MapPath will return the path under which it is run and the image must be
located in the data folder under that.

Tina said:
Yes, I know that. That's why I put the extra back slashes in the c#
version. Have you any idea why the C# version canot find the jpg?
T

chanmm said:
The backward slash (\) character can be used in a format string to turn
off the special meaning of
the character that follows it. For example, "\{" will cause a literal
"{"
to be displayed, and "\\" will
display a literal "\". The at sign (@) character can be used to
represent
an entire string verbatim. For
example, @"\\server\share" will be processed as \\server\share.

chanmm


I'm using 1.1/vs.net 2003 ...

C#example..............

string myPath = Server.MapPath(".\\Data\\" + (string)
Session["LogoFileName"]);

Produces this value in myPath

?myPath
@"c:\inetpub\wwwroot\CSharpCustomers\Data\GaryRocks.jpg"



VB example.............

Dim myPath As String = Server.MapPath(".\Data\" +
Session("LogoFileName"))

?myPath
"C:\Inetpub\wwwroot\CPCustomers\Data\GaryRocks.jpg"

the vb example works. the c# does not work. I notice that @
preceding
the string in the c# example. Could that be the difference? What am
I
doing wrong in the C# example?

thanks,
T
 
Back
Top