This topic is locked

Change Upload filename

3/16/2016 10:22:18 PM
ASPRunnerPro General questions
W
Wallaroo author

I have an ASP Runner 9.1 project which includes a file upload field. I want to customize this so that the uploaded filename is prepended with the username and upload date. File types will vary. I have tried using the script from the manual but it doesn't appear to work.
Here is what I am trying in a "Before Record Added" event -
if bValue(values("UploadLink")) then
set fileArray = CreateDictionary()
set fileArray = my_json_decode(values("UploadLink"))
Set objFSO = CreateObject("Scripting.FileSystemObject")
' rename files
for i = 0 to aspcount(fileArray)-1
fileName = fileArray(i)("name")
newFileName = "../documents/" & session("username") & "
" & formatDate(values("UploadDate"),"ddmmyyyy") & "_" & values("UploadLink")
sPath = left(getabspath(fileName),len(getabspath(fileName))-len(fileName))
objFSO.MoveFile getabspath(fileName) , sPath & newFileName
fileArray(i)("name") = newFileName
next
end if
' update values of the field that stores file names
values("UploadLink") = my_json_encode(fileArray)
When I try the script, I don't get an error response but no file name is entered into the field and the file is not uploaded.
Any help would be appreciated.

admin 3/22/2016

Here is the working code. This code assumes files are stored in "files" folder and you use Basic upload control.

d = Right("0" & Day(values("UploadDate")), 2)

m = Right("0" & Month(values("UploadDate")), 2)

y = Year(values("UploadDate"))
if values("UploadLink")<>"" then
Set objFSO = CreateObject("Scripting.FileSystemObject")

ext = Right(values("UploadLink"), 4)

fileName = "files\" & values("UploadLink")

newFileName = left(values("UploadLink"), len(values("UploadLink"))-4) & "_" & session("UserName") & "_" & d & m & y & ext
objFSO.MoveFile getabspath(fileName) , getabspath( "files\" & newFileName)
values("UploadLink") = newFileName
CustomQuery("update tbldocupload set UploadLink='" & newFileName & "' where DocID=" & keys("DocID"))
end if