Server.MapPath on a different server

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?
LVL 1
colin_palmerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mouattsCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
colin_palmerAuthor Commented:
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
mouattsCommented:
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
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

colin_palmerAuthor Commented:
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
mouattsCommented:
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
colin_palmerAuthor Commented:
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
mouattsCommented:
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
colin_palmerAuthor Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.