Server.MapPath

M

Miro

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
 
G

Guest

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

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

Mark Stevens

Have you tried specifying the path for the file using ~

"~/Products/ProductImages/" + filename

Regards,
Mark

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
--
|\ _,,,---,,_ 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".
 

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

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top