Wrox Programmer Forums
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old September 28th, 2004, 04:09 PM
Registered User
Join Date: Sep 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help with Server.MapPaths - aaaaaahhhh

Hi All

Sorry to be irate, but the whole concept of Server.MapPaths really has me in a tiswas!!

In order to confirm once and for all, could you please advise me on the following:

1) There is no difference in putting '/' or '\' in the Server.MapPath param, eg Server.MapPath("/fred/test.asp") or Server.MapPath("\fred\test.asp") - they work the same - correct?

2) I'm finally using my ISP's 'off-world' folder to store my Access DB (yes I know I should be using MSSQL) and I am trying to link my ASP files back to it using Server.MapPath in such a way that my ISP's file server structure and my local file server structure can read the same site without me having to have different connection strings for remote and local work.

To explain my problem, please note the following:

There are 2 folders to start with 1 called <htdocs> and 1 called <private>. The htdocs is the web share folder and the <private> one is the 'off-world' database store. A common practise I believe with IIS ISPs.

In the <htdocs> I have the following folder structures:

root level ... some ASP inc files ...

<incs> folder ... some ASP inc files ... <sprocs> folder ... some ASP inc files ...

<user-data> <pics> my uploaded pics

Now this is where the weirdie comes. If my ASP inc file is in the <incs><sprocs> level my Server.MapPath for accessing the <pics> folder is "../user-data/pics/", however if I have an ASP inc file in the <incs> level then my MapPath is "../../user-data/pics"

How is that?? Surely the <sprocs> folder would need more '../' than the <incs> folder which is one level up?

If somebody could just give me a dummies run-down on how this works I would really appreciate it as I just don't get it.



Old September 28th, 2004, 07:06 PM
Friend of Wrox
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41

Server.MapPath is indifferent on whether you use backslashes or forward slashes. If you do not put a forward or backward slash at the beginning of the string passed into Server.MapPath, the current directory that the ASP page is being executed is used as the base for the physical path. For example, if you had an ASP script running in the Inc directory, which had the physical path C:\InetPub\wwwroot\Inc, the following two lines:

<%= Server.MapPath("somefile.txt") %>
<%= Server.MapPath("/somefile.txt") %>

Would produce different output. The first line would use the current directory's physical path as the path for somefile.txt, and would output C:\InetPub\wwwroot\Inc\somefile.txt. The second line of code, due to the beginning forward slash, would use the root physical path, producing C:\InetPub\wwwroot\somefile.txt as the output.

Whats wrong with having two connection strings?
having a global.inc (or what ever you wish to call it) is a very handy file to hold connection strings, constants, dim commonly used variables, set mail constants etc.. This way you just comment one conn string out and uncomment your local one. As you are probably aware, hosts can often give us a dir structure we wouldt normaly use localy - why change to suit them. An example of how I use this file:

'const URLBase = "http://www.someAddress.com/labfit/"
 const URLBase = "http://localhost/labfit/"
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=C:\Inetpub\wwwroot\labfit\DB\dbName.m db"
'Conn.open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("../DB/dbName.mdb")

By using this method you change one file to make dramatic functional changes to your site. If you have your connection string in the head of every page that requires it, remove it, replace it with an include to a global file. If you replicate hosts dir structures every site you do, whats your local file system going to look like after you have built 50 web sites hosted by six different companys all using different dir set ups.

is your 'sprocks' folder inside your 'incs' folder? If so your "../../user-data/pics" path to your pics does not look correct
However, "../user-data/pics/" does, as you said wierd...

Wind is your friend
Old October 4th, 2004, 05:01 PM
Registered User
Join Date: Sep 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts

Hi Matt

Sorry for the delay in replying to you, but day-to-day work kept me from my PC - bah humbug!

Anyway your in-depth guide was spot on and has finally laid my demons to rest on this subject.

Many thanks.



Similar Threads
Thread Thread Starter Forum Replies Last Post
VB Express and SQL server on remote server questio HoosierDaddy61 Visual Basic 2005 Basics 0 February 22nd, 2006 11:27 AM
SQl Server license for a web server app carlos890 SQL Server 2000 1 December 8th, 2005 12:42 PM
SQL Server sync with net server and browser server ne SQL Server DTS 0 June 13th, 2005 06:29 PM
connecting web server and remote db server via asp moreyt Classic ASP Databases 0 May 31st, 2005 12:13 AM
[000] Unable to connect to server 'SERVER\SQL'; SQ ctanchan SQL Server 2000 1 August 15th, 2003 07:18 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.