Go Back   CodingForums.com > :: Server side development > ASP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average.
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-21-2002, 04:29 PM   PM User | #1
Mhtml
Senior Coder

 
Mhtml's Avatar
 
Join Date: Jun 2002
Location: Sydney, Australia
Posts: 3,531
Thanks: 0
Thanked 1 Time in 1 Post
Mhtml is an unknown quantity at this point
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..
Mhtml is offline   Reply With Quote
Old 07-21-2002, 07:00 PM   PM User | #2
QuackHead
Regular Coder

 
Join Date: Jun 2002
Posts: 344
Thanks: 0
Thanked 0 Times in 0 Posts
QuackHead is an unknown quantity at this point
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
QuackHead is offline   Reply With Quote
Old 07-22-2002, 01:13 AM   PM User | #3
Mhtml
Senior Coder

 
Mhtml's Avatar
 
Join Date: Jun 2002
Location: Sydney, Australia
Posts: 3,531
Thanks: 0
Thanked 1 Time in 1 Post
Mhtml is an unknown quantity at this point
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!
Mhtml is offline   Reply With Quote
Old 07-22-2002, 03:17 PM   PM User | #4
QuackHead
Regular Coder

 
Join Date: Jun 2002
Posts: 344
Thanks: 0
Thanked 0 Times in 0 Posts
QuackHead is an unknown quantity at this point
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
QuackHead is offline   Reply With Quote
Old 07-22-2002, 03:21 PM   PM User | #5
QuackHead
Regular Coder

 
Join Date: Jun 2002
Posts: 344
Thanks: 0
Thanked 0 Times in 0 Posts
QuackHead is an unknown quantity at this point
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
QuackHead is offline   Reply With Quote
Old 07-22-2002, 10:02 PM   PM User | #6
ReyN
New Coder

 
Join Date: Jun 2002
Location: Pilipinas
Posts: 89
Thanks: 0
Thanked 0 Times in 0 Posts
ReyN is an unknown quantity at this point
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")
__________________
aspxtreme
ReyN is offline   Reply With Quote
Old 07-23-2002, 08:51 AM   PM User | #7
Mhtml
Senior Coder

 
Mhtml's Avatar
 
Join Date: Jun 2002
Location: Sydney, Australia
Posts: 3,531
Thanks: 0
Thanked 1 Time in 1 Post
Mhtml is an unknown quantity at this point
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!
Mhtml is offline   Reply With Quote
Old 07-23-2002, 03:24 PM   PM User | #8
QuackHead
Regular Coder

 
Join Date: Jun 2002
Posts: 344
Thanks: 0
Thanked 0 Times in 0 Posts
QuackHead is an unknown quantity at this point
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
QuackHead is offline   Reply With Quote
Old 07-23-2002, 03:26 PM   PM User | #9
QuackHead
Regular Coder

 
Join Date: Jun 2002
Posts: 344
Thanks: 0
Thanked 0 Times in 0 Posts
QuackHead is an unknown quantity at this point
P.S. - I looked at your site.. none of the links work

Also... nice copy of the apple website

~Quack
QuackHead is offline   Reply With Quote
Old 07-24-2002, 07:07 AM   PM User | #10
Mhtml
Senior Coder

 
Mhtml's Avatar
 
Join Date: Jun 2002
Location: Sydney, Australia
Posts: 3,531
Thanks: 0
Thanked 1 Time in 1 Post
Mhtml is an unknown quantity at this point
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!
Mhtml is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:08 AM.


Advertisement
Log in to turn off these ads.