Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Server.MapPath

2 views
Skip to first unread message

Miro

unread,
Nov 20, 2009, 2:02:47 AM11/20/09
to
I cant seem to figure out why this doesnt work.

I have a folder structure like this:

<root>
default.aspx
test1.aspx (with an image control)
Folder_Products
test2.aspx (with an image control)
Folder_ProductImages
<image files...>

in each program i want to call a simple global function as below but when I
click "play" within visual studios the image does not display if i use the
server.mapPath. Notice how that line is commented.
But by doing this, Only test1.aspx can show the image and test2.aspx cannot.

Why doesnt server.mapPath properly work?
If I shoot that value to a textbox, it actually does show a valid url path.

Function ImagePathUrl_DesignBib(ByVal ImageName As String)

Dim DesignBibImageLocation As String
'Dim DesignBibImageLocation As String =
Server.MapPath("Products/ProductImages/" & ImageName.Trim)
DesignBibImageLocation = "Products/ProductImages/" & ImageName.Trim
Return DesignBibImageLocation
End Function

The only thing I can think of is that when I run it through vb...its somehow
blocked because of this port line:
http://localhost:49462/ then the aspx pages


Thanks,

Miro

Alexey Smirnov

unread,
Nov 20, 2009, 4:11:06 AM11/20/09
to
> blocked because of this port line:http://localhost:49462/then the aspx pages
>
> Thanks,
>
> Miro

Because the path parameter in the Server.MapPath method does not start
with a slash character, and it's mapped relative to the directory that
contains the aspx file. It works on test1.aspx because "Products/
ProductImages/..." is a child directory below root. It doesn't work
from test2.aspx because it has no "Products" in that directory. Change
Server.MapPath to start with a slash

("/Products/ProductImages/" & ImageName.Trim)

and try again.

Mark Stevens

unread,
Nov 20, 2009, 8:24:03 AM11/20/09
to
Have you tried specifying the path for the file using ~

"~/Products/ProductImages/" + filename

Regards,
Mark

--
|\ _,,,---,,_ A picture used to be worth a
ZZZzzz /,`.-'`' -. ;-;;, thousand words - then along
|,4- ) )-,_. ,\ ( `'-' came television!
'---''(_/--' `-'\_)

Mark Stevens (mark at thepcsite fullstop co fullstop uk)

This message is provided "as is".

0 new messages