I'm using ASP 3.0 on IIS 5.x, Win2K server.
I obtain a relative file path from a SQL database and need to establish whether or not the file exists, where it needs to be moved to, and whether it was successfully moved. All of this hinges on the Server.MapPath method, and right now I'm doing something wrong. Here is the code for the function that moves the file. I know for a fact that the file name is translating correctly (examples included):
<%
Function MoveFile(id, oldSL, newSL)
Dim objFSO
Set objFSO = Server.CreateObject("Scrip
ting.FileS
ystemObjec
t")
Dim mylocation, newLocation, myLongType
mylocation = filesrc
DebugW "mylocation", mylocation
Select Case myFileType
Case "TC"
myLongType = "Contracts"
Case "TL"
myLongType = "Letters"
Case "TP"
myLongType = "Proposals"
Case "TR"
myLongType = "Reports"
End Select
DebugW "myFileType", myFileType
DebugW "myLongType", myLongType
myLocation = myLocation & "/" & myLongType & "/SecurityLevel" & oldSL & "/"
newLocation = filesrc & "/" & myLongType & "/SecurityLevel" & newSL & "/"
DebugW "myLocation", myLocation
DebugW "newLocation", newLocation
dim objCommand, objRS
Set objCommand = Server.CreateObject("ADODB
.Command")
objCommand.ActiveConnectio
n = strConnect
objCommand.CommandText = "SELECT * FROM Documents WHERE Documents.ID = " & id
objCommand.CommandType = adCmdText
Set objRS = objCommand.Execute
Set objCommand = Nothing
dim src, dest
src = mylocation & objRS("FilePtr")
dest = newlocation & objRS("FilePtr")
DebugW "src", src
DebugW "dest", dest
Go '(Function which flushes response object buffer)
If src = dest Then
MoveFile = True
Else
Server.MapPath(src)
Server.MapPath(dest)
DebugW "Full src", src
DebugW "Full dest", dest
Go
DebugW "objFSO.FileExists(" & src & ")", objFSO.FileExists(src)
If objFSO.FileExists(src) Then
DebugW "objFSO.FileExists(" & dest & ")", objFSO.FileExists(dest)
If objFSO.FileExists(dest) Then
objFSO.DeleteFile dest, true
End If
objFSO.MoveFile src, dest
MoveFile = True
End If
End If
MoveFile = False
DebugW "MoveFile", MoveFile
End Function
%>
I'll walk through the execution.
The function gets parameters of ID, old Security Level and new Security Level. The SL's are integers which denote into which directory the file is placed.
filesrc is a globally declared variable which contains "admin/uploadfiles/".
The function then constructs the directory path - i.e. "admin/uploadfiles/Reports
/SecurityL
evel1/"
The file name is in the format "TX-######_#.*", where the first two characters denote the file type, the next 6 digits are the identification number (the concatenation of a two digit year and four digit IDinYr variable), and the final digit is a revision number ('version' in the database), i.e. "TR-040001_0.doc".
FilePtr is a record in the database which holds the file name, and is appended to the src and dest file paths.
I then attempt to map these paths to the server, evaluate existence, and move them.
The error I receive is that src and dest exceed the length of the parameter for the Server.MapPath method. I've seen varying documentation on the use of the parameter. Does it return a new path or does it modify the parameter? I've tried both implementations with the same error resulting.
The page that is executing this code is located in "C:\Inetpub\wwwroot\Inside
Trusant\ad
min\"
The file repositories are in "C:\Inetpub\wwwroot\Inside
Trusant\ad
min\upload
files\%Typ
e%\%Securi
tyLevel%\"
I am considering simply constructing the local physical path by hand, but if anyone knows why this is not working, I appreciate it.
-------------------------
Server.MapPath() error 'ASP 0214 : 80004005'
Invalid Path parameter
/InsideTrusant/admin/edit_
submit.asp
, line 69
The Path parameter excedes the maximum length allowed.
-------------------------
Any function such as DebugW or ErrorW is a debugging function that prints the value of the variable(s) passed to it. Go() flushes the response object buffer (Response.Flush()).
Start Free Trial