PureUpload delete file before delete/update

This tutorial explains how to delete a file before the update or delete sql statement is executed.
| User Level: | Intermediate |
|---|---|
| Server Model: | ASP VBScript |
|
This tutorial will explain how to delete a file while using an update form or a delete form in conjunction with PureASPUpload 1 & 2. The article of Paul Keur also explains this, but i had some questions from people which couldn't get the picture with all the code in the demo pages. It's actually very simple. First of all you will need to these two functions to make it work. <%
Find your code for either the delete or update sql statement that starts with: Delete statement: <% Update Statement: Just above these sql statements place the two functions as mentioned above. Then insert the code as shown below in the update or delete statement: ' execute the delete/update As you see it also will work for an update ! This is very handy when using it for example a news administration with images, where it is allowed to edit/change images. This way all images will be deleted from your system/server. One important note is that the database field that is called from the recordset, in this example (rsNews.Fields.Item("image").Value), needs to be opened before you call this database field. So, if your recordset is below the sql statement for update or delete, move it to the very top. Example code of the recordset: <% The below example would delete multiple files, uploaded with PureASPUpload. Creating a dynamic array and using the statement For Each..Next to get access to this array. Setting up the array with the fields of the database that holds the filename of the file uploaded: <% ImagePath1 = Server.MapPath("upload\") ImagePath2 = Server.MapPath("upload\") ImagePath3 = Server.MapPath("upload\") ImagePath4 = Server.MapPath("upload\") Dim ImageLibrary(3) Using the For Each..Next statement to access the array and set the delete action: If (Not MM_abortEdit) Then Hope this answers the requests for some people, for deleting multiple files. Note: the ending slash has to be in to make it work in the Server.MapPath.
For some reason it works with me without this slash (?)
|
Marcellino Bommezijn
Marcellino Bommezijn is one of the managers at dmxzone.com. He is a contributor on the tutorials section.
Owner of Senzes Media (http://www.activecontent.nl) which provides professional services and web applications for mid-sized companies.
ActiveContent CMS is the ASP.NET Content Management solution that is used for building professional and rich-featured websites.
User Reviews
Total of 38 reviewsVery neat, well done!
Written by student101 on June 6, 2008Very, Very neat, well done!Thank you for this one. Glad to know there are real coders out there. Cheers
Works one place and doesn't in the other
Written by Phillip Duncan on February 17, 2004I've got this working on a client server with the same host as mine, yet when I try to run it on my (same fields, different recordset name) is does not delete the images. The recordset is deleted and there are no errors given. The permissions are ...
Only deletes the first record - Please HELP!
Written by Peter Kutschmann on February 16, 2004First of all, MANY MANY thanks to Mr. Bommezijn for all your tutorials, it has helped me alot and I am sure many other people. Using your tutorial, I have created a delete multiple record page. This works perfectly. The problem is, all associated ...
No luck!
Written by Curtis Mulder on July 18, 2003I've moved the recordset in question to the top as suggested but still no luck. Below is the error. ADODB.Field (0x800A0BCD)Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current ...
Using with Smart Image Processor
Written by Phillip Duncan on June 19, 2003I modified the code to work with Smart Image Processor. I needed it to Delete the image and the Thumbnail that was created. I thought I'd post it in case anyone wants to do the same. Dim aspfile, Imagepath1, ImagePath2 ImagePath1 = ...
modify
Written by fabio nuñez on June 1, 2003If I use it in modify record the old files don't delete??
RE: Error
Written by Marcellino Bommezijn on June 1, 2003Please take a look at the comment below the one you posted. It discusses the same error as you have and the solution to it.







