Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10

Thread: Server.MapPath

  1. #1
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post

    Server.MapPath

    I'm getting better at asp but I can't figure out how to get server.MapPath to work for img src.

    I am including the file top.asp which is in the root of my site into every page. Top .asp contains the menu. When I include top.asp the images don't show and I can't figure out how I would use mappath to do it. Assuming you would use it anyway.

    Here is what I've used:
    Code:
    <% 
    var logo
    logo = server.MapPath ('images/pwshome_01.png');
    var menu
    menu = server.MapPath ('images/pwshome_03.png');
    var bgmenu
    bgmenu = server.MapPath ('images/pwshome_04.png');
    %>
    and then inserted
    Code:
    <img src="<%=logo%>">
    for each of them with their respective variable names. It is probably obvious but I'm new to this.

    pages in other directories will include to top.asp file.
    Also the menu (pwshome_03.png) image has an image map assigned .
    Thanks in advance, Mike...
    Last edited by Mhtml; 07-21-2002 at 04:31 PM.

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Posts
    344
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Make sure you use the FULL path to your directory...

    server.mapPath("c:\websitefolder\images\image.jpg")

    try that... let me know how it goes...

    ~Quack

  • #3
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post
    I tried that and it came up with
    Microsoft VBScript compilation error '800a03ea'

    Syntax error

    /pwshome/top.asp, line 3

    logo = server.MapPath ('c:\inetpub/wwwroot/pwshome/images/pwshome_01.png');
    -----------------------^
    Omnis mico antequam dominus Spookster!

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Posts
    344
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I don't know if this will make a difference or not, but try using full quotes instead of the single quote...

    Eg:

    Instead of:
    logo = server.MapPath ('c:\inetpub/wwwroot/pwshome/images/pwshome_01.png');

    Try this:
    logo = server.MapPath ("c:\inetpub/wwwroot/pwshome/images/pwshome_01.png")

    Notice that I also got rid of the semicolon on the end of that function. Unless you're using JScript as your ASP language, the semicolon is of NO use, and could cause trouble.

    ~Quack

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Posts
    344
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Lightbulb

    Oops, Sorry.. I missed some things here....


    I think I may have a fix for you.

    Looks to me like you're using JScript for your ASP Pages. I should've caught on to this...

    Well, now you need to make sure that you specify the default language for your ASP pages. You can do this at the start of each ASP page by writing:
    <%@Language=JScript%>

    By default, all asp pages are using VBScript as their default language. You can change these settings in IIS.

    For you to use JScript you need to specify that you are using it.

    forget my ealier post (unless you are in fact using VBScript) and just add this line to the top of your page.

    ~Quack

  • #6
    New Coder
    Join Date
    Jun 2002
    Location
    Pilipinas
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Server.MapPath should point to the complete file path as referenced from the virtual application root (your site's virtual root directory on the Web server).

    For example, if your virtual root is /mySite, and the image is in a subdir named images, use:

    Server.MapPath ("/mySite/images/whatever.jpg")

  • #7
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post
    Quackhead was quite right with his post. I had given up on the server.MapPath thing and gone on to learning about requesting and variables but decided to have another go at it and I got it working.

    I can now see exactly what my problem was and have a better understanding of MapPath, so I'll post it here in case some future users need to know.

    Firstly I was using Javascript without setting it as my default language <%@language=jscript%> (Thanks Quackhead).

    So, to make my initial example work I would need to have my page set out likt this
    Code:
    <%@language=jscript%>
    
    <% 
    var logo
    logo = Server.MapPath ("/mysite/images/logo.png")
    var menu
    menu = Server.MapPath ("/mysite/images/menu.png")
    var menubg
    menubg = Server.MapPath ("/mysite/images/menubg.png")
    %>
    
    
    <table background="<%=menubg%"> 
        <tr>
               <td><img src="<%=logo%>"><img src="<%=menu%>"></td>
        </tr>
    </table>
    Notice how I called the variables from outside the script using <%=variablename%>
    This above example is for Javascript, I'll show you how to do the VBscript version below
    Code:
    <%@language=VBscript%>
    <% 
    dim logo
    logo = Server.MapPath ("/mysite/images/logo.png")
    dim menu
    menu = Server.MapPath ("/mysite/images/menu.png")
    dim menubg
    menubg = Server.MapPath ("/mysite/images/menubg.png")
    %>
    
    
    <table background="<%=menubg%"> 
        <tr>
               <td><img src="<%=logo%>"><img src="<%=menu%>"></td>
        </tr>
    </table>
    Notice how I used DIM instead of VAR

    This is what I have learned... I will more than likely make a tutorial on my website CUBE for this so check in often to see more defenition of the script and how it works.

    Thanks, QuackHead and ReyN
    Mike...
    Omnis mico antequam dominus Spookster!

  • #8
    Regular Coder
    Join Date
    Jun 2002
    Posts
    344
    Thanks
    0
    Thanked 0 Times in 0 Posts
    No problem

    Sorry I didn't catch the JScript thing sooner, I should've seen that right away.

    I'm glad you got it all working now.

    Tip for the future, just to make your code easier to read, you should declare all your variables at the top of your pages ... not right before you're about to use them.

    ~Quack

  • #9
    Regular Coder
    Join Date
    Jun 2002
    Posts
    344
    Thanks
    0
    Thanked 0 Times in 0 Posts
    P.S. - I looked at your site.. none of the links work

    Also... nice copy of the apple website

    ~Quack

  • #10
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post
    It's still under construction.

    I was wondering if anyone would notice the copy. Took me a whilie to get that glass sought of effect on the images.
    Omnis mico antequam dominus Spookster!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •