View Full Version : Server.MapPath
Mhtml
07-21-2002, 04:29 PM
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:
<%
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 <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...
QuackHead
07-21-2002, 07:00 PM
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
Mhtml
07-22-2002, 01:13 AM
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');
-----------------------^
QuackHead
07-22-2002, 03:17 PM
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
07-22-2002, 03:21 PM
:o 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
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") :D
Mhtml
07-23-2002, 08:51 AM
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
<%@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
<%@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 (http://6sides.vze.com) for this so check in often to see more defenition of the script and how it works.
Thanks, QuackHead and ReyN
Mike...
QuackHead
07-23-2002, 03:24 PM
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
07-23-2002, 03:26 PM
P.S. - I looked at your site.. none of the links work :eek:
Also... nice copy of the apple website ;)
~Quack
Mhtml
07-24-2002, 07:07 AM
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.:)
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.