This is a discussion on Check if file already exist (using freeaspupload) within the ASP Development forums, part of the Programming & Scripting category; Hi All, Need help again here I'm using freeaspupload, and i modified a bit on renaming the file i've uploaded. ...
| |||||||
|
#1
| ||||
| ||||
| Hi All, Need help again here ![]() I'm using freeaspupload, and i modified a bit on renaming the file i've uploaded. The problem is if i upload the same filename, it gives me error like this : Microsoft VBScript runtime (0x800A003A) File already exists /web/ltl2009hostv4ok/www/corporate/upload.asp, line 181 I tried to put this code : Code: for each fileKey in Upload.UploadedFiles.keys
'SaveFiles = SaveFiles & Upload.UploadedFiles(fileKey).FileName & " (" & Upload.UploadedFiles(fileKey).Length & "B)"
strFileType = Left(Upload.UploadedFiles(fileKey).ContentType,5)
if strFileType = "image" or strFileType="appli" Then
'SaveFiles = SaveFiles & Upload.UploadedFiles(fileKey).FileName & " (" & Upload.UploadedFiles(fileKey).Length & "B) "
strFileName=Upload.UploadedFiles(fileKey).FileName
if inStr(strFileName,".jpg") or inStr(strFileName,".doc") or inStr(strFileName,".pdf") or inStr(strFileName,".docx") then
if not Upload.UploadedFiles(fileKey).Length>1000000 then
directory=uploadsDirVar & Upload.UploadedFiles(fileKey).FileName
'=====modified - start rename file=====
set fso = CreateObject("Scripting.FileSystemObject")
set file = fso.GetFile(directory)
file.name = session.Contents("ID") &"-"& strFileName
'=====start check if file exist====='
Dim objFSO, strFileNameUp
strFileNameUp = directory
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists (strFileNameUp) Then
DelFile = DelFile & strFileNameUp & ","
SaveFiles = "File is exist"
Else
SaveFiles = "File does not exist"
End If
'=====endcheck if file exist====='
myImageArray(counter) = file.name
counter = counter + 1
set file = nothing
set fso = nothing
'=====modified - end rename file======
else
DelFile = DelFile & Upload.UploadedFiles(fileKey).FileName & ","
SaveFiles = "File is too large, please attach smaller size"
end if
else
DelFile = DelFile & Upload.UploadedFiles(fileKey).FileName & ","
SaveFiles = "Invalid File Name, please attach the correct one"
end if
else
DelFile = DelFile & Upload.UploadedFiles(fileKey).FileName & ","
SaveFiles = "Invalid File Type, please attach the correct one"
end if
next
|
|
#2
| ||||
| ||||
| Could you highlight line 181?
__________________ Join the folding team |
|
#3
| ||||
| ||||
| Hi RR, sorry i just sort out the problem ^^ the previous error message is on : file.name = session.Contents("ID") &"-"& strFileName this code below works : Code: for each fileKey in Upload.UploadedFiles.keys
'SaveFiles = SaveFiles & Upload.UploadedFiles(fileKey).FileName & " (" & Upload.UploadedFiles(fileKey).Length & "B)"
strFileType = Left(Upload.UploadedFiles(fileKey).ContentType,5)
if strFileType = "image" or strFileType="appli" Then
'SaveFiles = SaveFiles & Upload.UploadedFiles(fileKey).FileName & " (" & Upload.UploadedFiles(fileKey).Length & "B) "
strFileName=Upload.UploadedFiles(fileKey).FileName
if inStr(strFileName,".jpg") or inStr(strFileName,".doc") or inStr(strFileName,".pdf") or inStr(strFileName,".docx") then
if not Upload.UploadedFiles(fileKey).Length>1000000 then
directory=uploadsDirVar & Upload.UploadedFiles(fileKey).FileName
'=====start modified rename file=====
set fso = CreateObject("Scripting.FileSystemObject")
set file = fso.GetFile(directory)
dim cekFile
cekFile=uploadsDirVar & session.Contents("ID") &"-"& Upload.UploadedFiles(fileKey).FileName
'=======start check if file exist========
if fso.FileExists(cekFile)=true then
response.write(cekFile&"already exists!")
DelFile = DelFile & Upload.UploadedFiles(fileKey).FileName & ","
SaveFiles = "File is already exist"
else
response.write(cekFile&"does not exist!")
file.name = session.Contents("ID") &"-"& strFileName
end if
'=======end check if file exist========
myImageArray(counter) = file.name
counter = counter + 1
set file = nothing
set fso = nothing
'=====end modified rename file======
else
DelFile = DelFile & Upload.UploadedFiles(fileKey).FileName & ","
SaveFiles = "File is too large, please attach smaller size"
end if
else
DelFile = DelFile & Upload.UploadedFiles(fileKey).FileName & ","
SaveFiles = "Invalid File Name, please attach the correct one"
end if
else
DelFile = DelFile & Upload.UploadedFiles(fileKey).FileName & ","
SaveFiles = "Invalid File Type, please attach the correct one"
end if
next
|
| The Following User Says Thank You to PhloooooIsFlo For This Useful Post: | ||
micky (November 19th, 2009) | ||
![]() |
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
| |
| ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [Error] ServiceModel does not Exist in namespace System | richyrich | .Net Development | 5 | October 17th, 2009 02:57 PM |
| Check Book | alansidman | Access Database Samples | 0 | June 7th, 2009 04:40 PM |
| Check box pop up information?? | dtz | JavaScript Programming | 4 | May 1st, 2009 07:21 AM |
| How do I check the tag of a child? | bryceowen | JavaScript Programming | 4 | February 19th, 2009 02:01 PM |
| [Database] Check if result set is empty | noFriends | PHP Development | 6 | June 27th, 2008 08:00 PM |