Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

aspUpload copyFile error

Status
Not open for further replies.

mwolf00

Programmer
Nov 5, 2001
4,177
US
I am using aspUpload and I am having an unusual problem. When I run the following code, the single line(after blue comment)works fine but when I replace it with the two lines after the red comment, I get an error saying "The process cannot access the file because it is being used by another process." when the .copyFile command runs. Even when I comment out the .createDirectory line, I still get the error when I try the .copyFile. Any ideas?

Code:
if inStr(request.serverVariables("CONTENT_TYPE"),"multipart/form-data") > 0 then
	dim upload, count, thisServer, fileNum, file
	set upload = server.createObject("Persits.Upload")
	
	thisServer = server.mapPath("../uploads/LRT/temp")
	count = upload.save(thisServer)
	
	if count = 1 then
		'a new file now resides in the temp folder
		dim newFile, newFileName
		dim oldFilePath
		set newFile = upload.files("newFile")
		
		If Not newFile Is Nothing Then
			if newFile.ext = ".xls" then
				newFileName = "LRT - " & upload.form("leaseNumber") & ".xls"
				oldFilePath = server.mapPath("../uploads/LRT/" & newFileName) 
				if upload.fileExists(oldFilePath) then
					[COLOR=red]these next two lines cause a "file in use" error when run[/color]
					[b]upload.createDirectory server.mappath("../uploads/LRT") & "/DEL", true
					upload.copyFile oldFilePath, replace(oldFilePath, "/LRT/", "/LRT/DEL/"), true[/b]
					[COLOR=blue]this line works fine when I run it separately[/color]
					[b]upload.copyFile oldFilePath, replace(oldFilePath, "LRT -", "DEL -"), true[/b]
				end if
			end if
		End If
	end if
	response.end
end if

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
Perhaps the Upload object is keeping a refernce to the file or a pessimistic lock on it until it [upload object] is de-referenced?

Actually, the longer I look at it, the longer I can't figure out why that would be failing...I mean you can obviously vopy the file, so it can't be a lock, but maybe the directory isn't being created fast enough...thats just wierd htouhg. Looks like a failure in the Upload object....

Maybe try creating the folder with an FSO object instead? Less efficient to do it that way but it may get around any error present in the Upload object (which is likely using FSo itself, but hell if I can tell what it is doing wrong, that action seems fairly simple).

-T

barcode_1.gif
 
Tarwyn,

Thanks for the reply but the problem is that this line of code runs:
upload.copyFile oldFilePath, replace(oldFilePath, "LRT -", "DEL -"), true


and this one doesn't:
upload.copyFile oldFilePath, replace(oldFilePath, "/LRT/", "/LRT/DEL/"), true

even when I remove the .createDirectory line altogether (since it only needed to run once and the directory now exists)

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
Is it possible the replace isn't occurring correctly? If that was the case then it would be trying to copy the file over top of an existing file. Or worsxe, whats to keep there from already being a file in the DEL folder by that name, is it possible it isn't letting your overwrite an already duplicated file?

barcode_1.gif
 
DOH!!!! *&%^*^ %&^*& ^$&%$R^ %$%$#*(&^ ARGH!!!!

Darn backslashes!!!!!
upload.copyFile oldFilePath, replace(oldFilePath, "/LRT/", "/LRT/DEL/"), true

should be

upload.copyFile oldFilePath, replace(oldFilePath, "\LRT\", "\LRT\DEL\"), true

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
Thanks everyone!

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top