Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Server.MapPath on a different server

Posted on 2004-10-28
8
Medium Priority
?
897 Views
Last Modified: 2008-01-09
Hi Experts,

I have written a page that goes through a recordset of Photo IDs in the database and checks if the file of the same name exists in a physical folder. This works. However I dont know how to check a physical folder on a different server.

For example:
photoPath = "\\servername\images$"
strPhysicalPath = Server.MapPath(photoPath)

I thought the above would work but I get the error:

Server.MapPath() error 'ASP 0174 : 80004005'
Invalid Path Character(s)

How do I do this?
0
Comment
Question by:colin_palmer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 11

Accepted Solution

by:
mouatts earned 1400 total points
ID: 12431709
Permission tend to be a problem here as the user under which IIS is running needs to be entitled to log on to the other machine.

The easiest way to do this is to create a virtual directory in IIS that points to the relevent directory on the other machine. This will allow you enter the relevent user account and password then within your mappath you can specify the virtual directory eg

If the remote server/directory  is \\server2\images and you set up a virtual directory called images2 that points to this the your code will look like this

photoPath = "\images2"
strPhysicalPath = Server.MapPath(photoPath)

HTH
Steve
0
 
LVL 1

Author Comment

by:colin_palmer
ID: 12431792
Hi Steve

I did what you said and created a new Virtual Directory and its permissions, say its called 'images2'  and its pointing to '\\server2\images':

If I goto my browser and type the URL e.g. http://servername/images2/filename.jpg 

I can see the file so that part of it is working.

So I tried

photoPath = "\images2"
strPhysicalPath = Server.MapPath(photoPath)

However, I am getting the error:

Microsoft VBScript runtime error '800a004c'
Path not found

Isnt the MapPath looking for the physcial folder instead of the Virtual Directory? Is there a way to get the Server.MapPath to see the Virtual Directory I created?
0
 
LVL 11

Expert Comment

by:mouatts
ID: 12431952
Actually I've just twigged what you are trying to do and I don't think that you really need to use mappath.

I presume you are using the FileSystemObject et al to check for the existence of file. In which case just use the full UNC path when you check the file. If permissions are a problem here then either grant the appropriate permissions on the remote server or set the directory up as a network drive and use the drive letter in the FSO stuff.

There are some glitches when using UNC which may be the problem that you have had with the mappath. Certainly on a system I worked on recently when you did a password change on the local machine the remote path became inaccessible via IIS but ok via Explorer. The solution was to go to lunch and hope it worked when you got back!

HTH
Steve
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:colin_palmer
ID: 12431986
This is the code im using:

<!--#include file="connection.asp" -->
<html>

<body bgcolor="#FFFFFF" text="#000000">
<%
'Create a recordset object
Set rstRange = Server.CreateObject("ADODB.Recordset")

      ' Find Names of people who have withheld their photos
      SQL = "SELECT ID AS ID, FIRST_NAME ++ ' ' ++ SUR_NAME AS Name "
      SQL = SQL & "FROM  tb_Staff_Member "
      SQL = SQL & "WHERE (PHOTO = N'with_held.jpg') "
      SQL = SQL & "ORDER BY SUR_NAME "
      rstRange.Open sql,ObjConn,adOpenKeyset
      %>
      
<table  border="1" align="center">
  <tr>
    <td colspan="2">
      <div align="center"><b>Members of Staff Who have with held their Photos</b></div>
    </td>
  </tr>
  <tr>
    <td>
      <div align="center"><b>ID</b></div>
    </td>
    <td>
      <div align="center"><b>Name</b></div>
    </td>
  </tr>
  <%
  while NOT rstRange.EOF
  %>
  <tr>
    <td><%=rstRange("ID")%></td>
    <td><%=rstRange("Name")%></td>
  </tr>
  <% rstRange.MoveNext
  Wend
  rstRange.Close
  %>
</table>

      
<p align="center">Building Table........... This requires a search of the photo
  files Please wait .........</p>

<table  border="1" align="center">
  <tr>
    <td colspan="2">
      <div align="center"><b>Members of Staff Who have No Photos</b></div>
    </td>
  </tr>
  <tr>
    <td>
      <div align="center"><b>ID</b></div>
    </td>
    <td>
      <div align="center"><b>Name</b></div>
    </td>
  </tr>
  <%
dim strPathInfo, strPhysicalPath,strPath, objFolder, objSubFolders, objFSO, objFile, photoPath
dim objFolderContents,objFileItem, MyFile
photoPath = "StudentPhotos"
strPhysicalPath = Server.MapPath(photoPath)

Response.write "This file is: " & strPhysicalPath

set objFSO = CreateObject("Scripting.FileSystemObject")

set obJFolder = objFSO.GetFolder(strPhysicalPath)
set objFolderContents = objFolder.Files

sql = "SELECT ID AS ID, FIRST_NAME ++ ' ' ++ SUR_NAME AS Name  FROM tb_staff_Member ORDER BY SUR_NAME"
rstRange.Open sql,ObjConn,adOpenKeyset
rstRange.MoveFirst

      DO WHILE NOT rstRange.EOF
      checkID = rstRange("ID")
      
            For each objFileItem in objFolderContents
                  if checkID = Left(objFileItem.name,8) THEN
                  found = true
                  EXIT FOR
                  Else
                  found = false
                  end if
            next
            
            if found = false then
            Response.Write "<tr><td>" & checkID & "</td>"
            Response.Write "<td>" & rstRange("NAME")& "</td></tr>"
            count = count + 1
            end if
            
      rstRange.MoveNext
      LOOP
      Response.Write "<tr><td>Total</td><td>" & count & "</td></tr>"
      rstRange.Close
      
%>
</table>
<p>
</body>

</html>
<!--#include file="footer.asp" -->
0
 
LVL 11

Expert Comment

by:mouatts
ID: 12432068
Try this

strPhysicalPath = "\\server2\StudentPhotos"

Response.write "This file is: " & strPhysicalPath
set objFSO = CreateObject("Scripting.FileSystemObject")
set obJFolder = objFSO.GetFolder(strPhysicalPath)
set objFolderContents = objFolder.Files
0
 
LVL 1

Author Comment

by:colin_palmer
ID: 12432141
Hi Steve

your help is much appreciated, I tried the above and am still getting path not found error.

If I type the URL in my browser: http://mars/hydraphotos/photoID.jpg 
this works

So I also tried

strPhysicalPath = "http://mars/hydraphotos"

This does not work either. Very weird.
0
 
LVL 11

Expert Comment

by:mouatts
ID: 12432209
No you can't use http with FSO you will need to use either the UNC or map the directory and use the drive letter eg

strPhysicalPath="\\mars\hydraphotos"

or assuming mapped to e:

strPhysicalPath="e:\"

Steve
0
 
LVL 1

Author Comment

by:colin_palmer
ID: 12432345
Hi Steve

I still cannot see the folder contents on another server so I decided to copy the contents of the folder into a folder on the same server as the webpage and then ill write a batch file to copy any new files added to the folder.

Many thanks for you help, you deserve the points

regards

Colin
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question