Multiple Image Delete & Remove Options for Pure ASP Upload

This tutorial is the second of a three part series on image delete options using George Petrov's Pure ASP upload. The first shows how to handle image delete and remove options on an update form with a single image. This tutorial looks at update forms with multiple image fields. Having more than one image imposes limitations on image remove and delete options, but with a bit of imaginative thinking and a little hand coding we'll see that we can provide users with a full array of image handling options.

If the user uploads a new image, this how we determine which image is being updated if any and delete the old file.

' check to see if the user has replaced an image and delete old image the value in red should match the name of the image field in your form
' set path to images folder
ImagePath = Server.MapPath("..\site_images\")
' find our what image is replaced and delete old image
if UploadFormRequest("P_Image1") <> "" Then
'create file scripting object
Set File = CreateObject("Scripting.FileSystemObject")
ImageFile = ImagePath & "\" & (rs_about.Fields.Item("P_image1").Value)
' check if file exists and if true delete the file
If fileExists(ImageFile) Then
File.DeleteFile(ImageFile)
End If
end if
if UploadFormRequest("P_Image2") <> "" Then
'create file scripting object
Set File = CreateObject("Scripting.FileSystemObject")
ImageFile = ImagePath & "\" & (rs_about.Fields.Item("P_image2").Value)
' check if file exists and if true delete the file
If fileExists(ImageFile) Then
File.DeleteFile(ImageFile)
End If
end if
if UploadFormRequest("P_Image3") <> "" Then
'create file scripting object
Set File = CreateObject("Scripting.FileSystemObject")
ImageFile = ImagePath & "\" & (rs_about.Fields.Item("P_image3").Value)
' check if file exists and if true delete the file
If fileExists(ImageFile) Then
File.DeleteFile(ImageFile)
End If
end if

'end delete image code

So that's it after this the stock UD generated code executes the update query and that's all there is to it. There are few holes in this, but it is about as close we are going to get to perfect world. Don't forget to download the sample application and the tutorial.pdf.

MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close
If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editRedirectUrl)
End If
End If
End If
%>

Download Tutorial Files First Page> > >>

James Threadgill

James ThreadgillJames Threadgill has authored numerous tutorials on ASP and ASP.NET web development, published on such sites as the Dynamic Zones and MSDN Accademic Alliance. He co-authored the Sam's book Dreamweaver MX: ASP.NET Web Development.

James first began computer programming in 1995 while attending Alvin Community College. He completed a certificate of computer science program and an Associate of Arts degree at Alvin before going on to the University of Houston-Clear Lake where he was awarded a Bachelor of Science and a Master of Arts.

James publishes fiction, poetry, and visual arts under the name Wayne James. His fiction first appeared in Raconteur in 1995 and since has been published numerous times: in Hadrosaur Tales 5 and 7, Bayousphere, and in the Write Gallery e-zine. His poetry first appeared in the small press magazine Lucidity in 1996 and has been published numerous times since. His collection of fiction and poetry, When Only the Moon Rages, was released in 2000. Most recently his work appeared in Tales of the Talisman winter 2010 and spring 2011 issues. James currently attends graduate school at the University of Houston and owns and operates small web design and internet marketing firm, WWWeb Concepts, with his wife, Karen, in Houston, TX USA.

See All Postings From James Threadgill >>

Comments

remove checkbox

October 8, 2003 by Marcello Citzia
Is there a possibility to insert a checkbox removeĀ for every single image?

How do I remove just 1 or 2 images?

September 11, 2004 by John Tucker

How can I use checkbox to "delete_images1" , "delete_images2" and "delete_images3" with out deleting all images?

You must me logged in to write a comment.