DeveloperBarn Forums

DeveloperBarn

Programming & IT forum

Check if file already exist (using freeaspupload)

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. ...

Go Back   DeveloperBarn Forums > Programming & Scripting > ASP Development

  #1  
Old November 19th, 2009, 05:57 AM
PhloooooIsFlo's Avatar
Barn Regular
 
Join Date: Jul 2008
Location: Indonesia
Posts: 54
Rep Power: 2
PhloooooIsFlo is on a distinguished road
Default 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 =)
Reply With Quote
  #2  
Old November 19th, 2009, 08:19 AM
richyrich's Avatar
Administrator
 
Join Date: Mar 2008
Real name: Rich
Location: Somewhere only we know...
Posts: 1,312
Blog Entries: 5
Rep Power: 8
richyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to all
Default

Could you highlight line 181?
__________________
Join the folding team
Reply With Quote
  #3  
Old November 19th, 2009, 08:24 AM
PhloooooIsFlo's Avatar
Barn Regular
 
Join Date: Jul 2008
Location: Indonesia
Posts: 54
Rep Power: 2
PhloooooIsFlo is on a distinguished road
Default

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 ^^

Comments on this post
micky agrees: Thanked Post
Reply With Quote
The Following User Says Thank You to PhloooooIsFlo For This Useful Post:
micky (November 19th, 2009)
  #4  
Old November 19th, 2009, 08:28 AM
richyrich's Avatar
Administrator
 
Join Date: Mar 2008
Real name: Rich
Location: Somewhere only we know...
Posts: 1,312
Blog Entries: 5
Rep Power: 8
richyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to all
Default

No problem. Glad you got it sorted...
Reply With Quote
Reply

  DeveloperBarn Forums > Programming & Scripting > ASP Development

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads

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


All times are GMT -4. The time now is 02:04 AM.


Copyright ©2008-2009, DeveloperBarn

Content Relevant URLs by vBSEO 3.3.2