Submit the file using Response.BinaryWrite () and delete it afterwards
As part of a classic ASP project, the user should be able to upload a file that is dynamically retrieved from the zip archive and sent via Response.BinaryWrite () by simply calling "document.asp? Id = [some id here]".
Checkout and upload is not a problem, but I need to delete the checked out file after the upload is complete. I have never done ASP or VBA before and I wonder why I am stuck here.
I tried to delete the file right after Response.WriteBinary () using FileSystemObject.DeleteFile (), but this results in a 404 error on the client side.
How can I wait for the download to complete and take additional steps?
Edit: This is how my code looks like:
'Unzip a specified file from an archive and put it path in *document*
set stream = Server.CreateObject("ADODB.Stream")
stream.Open
stream.Type = 1 ' binary
stream.LoadFromFile(document)
Response.BinaryWrite(stream.Read)
'Here I want to delete the *document*
source to share
I found a solution: the extracted files are saved in a special directory and every time the user runs document.asp it checks that directory for files older than one hour and deletes them.
I think this is the easiest way to manage, but also, I would prefer a solution where the document is deleted after upload.
source to share
I suspect that the point you are calling with the DeleteFile method, the file you are trying to delete is currently locked by something else, the question is what?
Try to include: -
stream.Close()
after your BinaryWrite. Also make sure you have done a similar thing with the component you used to extract the file. If the component does not offer any "private" obviouse methods, they try to assign to the Nothing
variables that reference them.
source to share