strange c# - vb difference

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
 
M

Michael A. Covington

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.
 
C

chanmm

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
 
T

Tina

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.
 
T

Tina

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
 
J

james.curran

I have no idea why it cannot find the jpg. You are sure the jpg is in
BOTH folders?
 
G

Guest

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
 
T

Tina

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top