Alpha DevCon 2018
Results 1 to 5 of 5

Thread: Deleting File from Image File Reference Field value

  1. #1
    Member
    Real Name
    Bob Courtemanche
    Join Date
    Feb 2008
    Posts
    35

    Default Deleting File from Image File Reference Field value

    Hello,

    I'm a little stuck and could use a push.

    I would like the ability to delete a file that is stored in a folder and referenced from an Image File Reference Field in a grid called Images. I have Allow Delete enable in the Update Settings: Permissions portion of the Grid. This only allows deleting the reference in the grid. I’d like to get to the file. The client folder for uploading images is created when creating a new client account. I have a form event on the Images.a5w page to allow the uploading of the files. The filename is stored in the Name Field of the grid.

    I assume I need a script in the Event: CanDeleteRecord before the end with. How can I get the filename from the field Name of the grid based on the user selecting the delete checkbox? I’ve looked at the Xbasic for the grid and don’t know how to tie the two together. Any help would be appreciated.

    filename = ????
    if (filename = "") then
    end
    end if
    If file.exists("[PathAlias.ADB_Path]\client\\" + session.vFldr + "\\" + filename)
    a5_file_remove("[PathAlias.ADB_Path]\client\\" + session.vFldr + "\\" + filename)
    end if

    From the grid
    with tmpl.field_info[3]
    .Fieldname = "Name"
    .Scope = "Local"
    .DisplayFormat = ""
    .DisplayUnFormat = ""
    .Type = "C"
    .Updateable = .f.
    .Varname = "NAME"
    .Column.LabelPosition = "Left"
    .Controltype = "Label"
    .Label.InLineStyle = ""
    .BreakType = "None"
    .nCols = 1
    .Column.Hide = .f.
    .Column.Heading = "Name"
    .Column.Sort = "Name"
    .Column.Type = "Freeform"

    Thanks for any help,

    Bob

  2. #2
    Moderator Steve Wood's Avatar
    Real Name
    Steve Wood
    Join Date
    Nov 2003
    Location
    Bay Area, California
    Posts
    8,775

    Default Re: Deleting File from Image File Reference Field value

    Here is an example of additional processing based on that Delete box being checked. It builds a crlf delimited list of which records are checked for delete. Then you can process for each of those records in the last three statements.

    ---

    dim chkrows as n

    with tmpl_userlist
    componentName = "mycomponent"
    chkrows = rows
    end with

    '' DELETE CODE
    dim deletelist as c
    for i = 1 to chkrows
    if eval_valid("V.R"+alltrim(str(i))+".CheckBox_Delete") = .T. 'delete checked
    deletelist = deletelist + eval("V.R"+alltrim(str(i))+".userid") + crlf() ' assuming the field was named 'userid'
    end if
    next

    for each foo in deletelist
    ...put your code here to delete the file
    next
    Steve Wood
    Join the ALPHA DEVELOPERS NETWORK
    There is no Cloud. It's just someone else's computer.
    Web - Mobile - Hosting - Products - Frameworks - Developer Resources
    AlphaToGo | IADN (100% Alpha Anywhere Websites)

  3. #3
    Member
    Real Name
    Bob Courtemanche
    Join Date
    Feb 2008
    Posts
    35

    Default Re: Deleting File from Image File Reference Field value

    I eventually got around to attempting this and I am having problems with my delete code. The path is good. I tested it wth an actual file name in the client folder. What I can figure is how to get the Name (a character field in the grd_image table which has the name of the file) from the grid for the selected to delete record.

    ---

    dim chkrows as n
    with tmpl_grd_image
    componentName = "grd_image"
    chkrows = rows
    end with

    ' DELETE CODE
    dim deletelist as c
    for i = 1 to chkrows
    if eval_valid("V.R"+alltrim(str(i))+".CheckBox_Delete") = .T. 'delete checked
    deletelist = deletelist + eval("V.R"+alltrim(str(i))+".CheckBox_Delete") + crlf()
    end if
    next

    for each foo in deletelist
    If file.exists("[PathAlias.ADB_Path]\client\\" + session.vFldr + "\\" + name)
    a5_file_remove("[PathAlias.ADB_Path]\client\\" + session.vFldr + "\\" + name)
    end if
    next

    ---

    I tried the following for the end of the If file.exists(.... \\ ??? ) and a5_file remove( \\ ???)

    alltrim(tmpl.field_info[3])
    tmpl not found.

    alltrim(datasubmitted.name)
    datasubmitted.name subelement not found

    alltrim(tmpl_name)
    Variable "tmpl_name" not found

    alltrim(.name)
    Argument is incorrect data type

    alltrim(name)
    Variable "name" not found

    ".name"
    no error, just does not delete the file

    name
    Variable "name" not found

    I'm just guessing at this point. Any suggestion on how to get the filename from the grid field?

    Thanks,

    Bob

  4. #4
    Moderator Steve Wood's Avatar
    Real Name
    Steve Wood
    Join Date
    Nov 2003
    Location
    Bay Area, California
    Posts
    8,775

    Default Re: Deleting File from Image File Reference Field value

    Just like the checkbox is named V.Rx.CheckBox_Delete (where X is the row), your other field names have a similar structure. V.R1.Filename, V.R2.Filename, etc. You have to use the same logic as deployed for knowing the delete button, that is you, you need to cycle through each row and process, or not process, each row based on your criteria. Meaning, you cannot determine in advance if your desired record is R1, R2 or Rn.
    Steve Wood
    Join the ALPHA DEVELOPERS NETWORK
    There is no Cloud. It's just someone else's computer.
    Web - Mobile - Hosting - Products - Frameworks - Developer Resources
    AlphaToGo | IADN (100% Alpha Anywhere Websites)

  5. #5
    Member
    Real Name
    Denis Ahmet
    Join Date
    Jul 2005
    Location
    United Kingdom
    Posts
    986

    Default Re: Deleting File from Image File Reference Field value

    Hi,

    I need to delete a file from a folder in an application i wrote a few years ago. Can anyone help with the code where the file is deleted from a directory?

    dim chkrows as n
    with tmpl_grd_image
    componentName = "grd_image"
    chkrows = rows
    end with

    ' DELETE CODE
    dim deletelist as c
    for i = 1 to chkrows
    if eval_valid("V.R"+alltrim(str(i))+".CheckBox_Delete") = .T. 'delete checked
    deletelist = deletelist + eval("V.R"+alltrim(str(i))+".CheckBox_Delete") + crlf()
    end if
    next

    for each foo in deletelist
    If file.exists("[PathAlias.ADB_Path]\client\" + session.vFldr + "\" + name)
    a5_file_remove("[PathAlias.ADB_Path]\client\" + session.vFldr + "\" + name)
    end if
    next
    Thanks,

    Denis

Similar Threads

  1. image file reference field on runtime network
    By TheseNutts in forum Alpha Five Version 8
    Replies: 9
    Last Post: 05-19-2008, 10:47 AM
  2. image file reference field question
    By martinwcole in forum Alpha Five Version 7
    Replies: 1
    Last Post: 07-21-2006, 09:45 PM
  3. Image File Reference Field
    By gloala in forum Alpha Five Version 7
    Replies: 2
    Last Post: 06-29-2006, 01:19 PM
  4. Use character field to reference image file
    By Howard G. Cornett in forum Alpha Five Version 6
    Replies: 3
    Last Post: 08-01-2005, 07:59 PM
  5. Image file reference field problem on reports.
    By PhilD in forum Alpha Five Version 5
    Replies: 6
    Last Post: 12-23-2003, 06:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •