Link to home
Create AccountLog in
Avatar of XGIS
XGISFlag for Australia

asked on

VB Script to Delete File in Folder using in ASPMAKER (CLASSIC ASP)

I have a CLASSIC ASP project that is Generated using ASPMAKER 10.1
You need to use ASPMAKER (which is a free download, with NO restrictions)

A sample complete functional project and database is supplied as an attachment. You actually need to rename the attached AGP file since this site is so 1920's. I have renamed it .XML, as it is ONLY an XML file but using the extension AGP.

To generate the code takes less than a minute, before the application is ready for use.

I need to delete the image files using VB script. The image names are in the database.
The path to each image is created based on the SiteID for each row. This happens when the file is uploaded.  The code also renames the file and stores that name in the database, as well as the original name.

The row of data is not being deleted, just the image and the data held in the two database fields that store the New Custom Name and the actual Original Name.

There are 4 basic events that are targeted and used by ASPMAKER
The solution to this question needs to target the "Row_Deleting" event;

Other related events are Row_Inserting (working sample attached), Row_Updating, and Row_Rendered.

The sample code below shows how the "Row_Inserting" event is used to create a folder and rename and write the file.

'Row Inserting event
Function Row_Inserting(rsold, rsnew)
If Not EW_DEBUG_ENABLED Then On Error Resume Next
' Various code notes 
' Please note that folder path is relative to application root, NOT destination folder. So you can either:
' The parent path is the primary issue that prevents the code from displaying the newly uploaded
' images and deleting images.

Dim dot  ' this is the code from the txt file.
dot = "."      
Dim siteid 'The ID of the record being created 
siteid = SiteIDMax + 1 'Runs this function stored in Global Codes..... SiteIDCount = ew_ExecuteScalar("SELECT COUNT(*) FROM <table>")
Dim folderpath                                          
folderpath = "../App_Data_Sites/" & siteid & "/"     
                         
  If  len(rsnew("Image1"))>0 then           
            Image1.UploadPath = folderpath ' the folder path in subsequent row render (to list or view
            ' also this path in row_deleting to do the same for delete replace etc
            Dim origname1 'the original uploaded file name in case you have to refind "image0001.jpg"  
            origname1 = rsnew("Image1")' get the original name from the upload
            rsnew("Image1OriginalName")=origname1 'store original name here          
            Dim image1Type                   
            image1Type = dot & Split(origname1, ".")(UBound(Split(origname1, "."))) 
            rsnew("Image1") = "DMP_Site_" & siteid & "_Image_1" & image1Type  
              Else
           Row_Inserting = False  
        End If                                   
                                             
    
      Row_Inserting = True 
End Function    

Open in new window


Essentially the code just needs to reference the path based on the SITEID (eg Session.SiteID), find the name for "Image1" and delete the file corresponding with that name.
ASPMAkerProject-DB-ImageUploadPa.zip
ASKER CERTIFIED SOLUTION
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer