+ Reply to Thread
Results 1 to 4 of 4

Thread: Check if file already exist (using freeaspupload)

  1. #1
    Barn Frequenter PhloooooIsFlo is on a distinguished road PhloooooIsFlo's Avatar
    Join Date
    Jul 2008
    Location
    Jakarta, Indonesia, Indonesia
    Posts
    109
    Rep Power
    4

    Check if file already exist (using freeaspupload)

    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
    
    Does anyone can help? thank you in advance =)

  2. #2
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Could you highlight line 181?

  3. #3
    Barn Frequenter PhloooooIsFlo is on a distinguished road PhloooooIsFlo's Avatar
    Join Date
    Jul 2008
    Location
    Jakarta, Indonesia, Indonesia
    Posts
    109
    Rep Power
    4

    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
    
    Sorry to waste your time here, RR ^^

  4. #4
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    No problem. Glad you got it sorted...

+ Reply to Thread

Similar Threads

  1. Check if result set is empty
    By noFriends in forum PHP Development
    Replies: 9
    Last Post: July 8th, 2011, 10:06 AM
  2. ServiceModel does not Exist in namespace System
    By richyrich in forum .NET Development
    Replies: 5
    Last Post: October 17th, 2009, 03:57 PM
  3. Check Book
    By alansidman in forum Access Database Samples
    Replies: 0
    Last Post: June 7th, 2009, 05:40 PM
  4. Check box pop up information??
    By dtz in forum JavaScript Programming
    Replies: 4
    Last Post: May 1st, 2009, 08:21 AM
  5. How do I check the tag of a child?
    By bryceowen in forum JavaScript Programming
    Replies: 4
    Last Post: February 19th, 2009, 02:01 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO