colin_palmer
asked on
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?
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
ASKER
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")%></t d>
<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,objFileI tem, MyFile
photoPath = "StudentPhotos"
strPhysicalPath = Server.MapPath(photoPath)
Response.write "This file is: " & strPhysicalPath
set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
set obJFolder = objFSO.GetFolder(strPhysic alPath)
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" -->
<!--#include file="connection.asp" -->
<html>
<body bgcolor="#FFFFFF" text="#000000">
<%
'Create a recordset object
Set rstRange = Server.CreateObject("ADODB
' 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></
</td>
<td>
<div align="center"><b>Name</b>
</td>
</tr>
<%
while NOT rstRange.EOF
%>
<tr>
<td><%=rstRange("ID")%></t
<td><%=rstRange("Name")%><
</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></
</td>
<td>
<div align="center"><b>Name</b>
</td>
</tr>
<%
dim strPathInfo, strPhysicalPath,strPath, objFolder, objSubFolders, objFSO, objFile, photoPath
dim objFolderContents,objFileI
photoPath = "StudentPhotos"
strPhysicalPath = Server.MapPath(photoPath)
Response.write "This file is: " & strPhysicalPath
set objFSO = CreateObject("Scripting.Fi
set obJFolder = objFSO.GetFolder(strPhysic
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" -->
Try this
strPhysicalPath = "\\server2\StudentPhotos"
Response.write "This file is: " & strPhysicalPath
set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
set obJFolder = objFSO.GetFolder(strPhysic alPath)
set objFolderContents = objFolder.Files
strPhysicalPath = "\\server2\StudentPhotos"
Response.write "This file is: " & strPhysicalPath
set objFSO = CreateObject("Scripting.Fi
set obJFolder = objFSO.GetFolder(strPhysic
set objFolderContents = objFolder.Files
ASKER
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.
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.
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\hy draphotos"
or assuming mapped to e:
strPhysicalPath="e:\"
Steve
strPhysicalPath="\\mars\hy
or assuming mapped to e:
strPhysicalPath="e:\"
Steve
ASKER
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
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
ASKER
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?