X Delete File

This server behavior provides you the way to physically remove unwanted files from the server and it can be combined with the DW's Delete Record.

Applying

Before applying it you will have to create a form which will post the file url to be deleted. This may be done statically using a text field where the user insert the relative path of the file, or dynamically creating a recordset and binding the url source to the element, in this way you may also delete the record from database using the Delete Record in combination. The behavior can be applied multiple times on the same page using the same form or using more than one form each with its Delete button.

Form: Select the form that will delete the file.
Aux Path: This auxiliary path is an optional in case you have saved into database only the name of the file. For instance if you have saved 'myfile.doc' and the location is inside the folder 'doc' on the same level of the script the auxiliary path would be "doc/".
File: Select here the element that contains the location of the file. If this contains the exact relative path to the file it would be no need to use the Aux Path to complete it, otherwise you better use it.
Error Msg: Insert a message to warn that the specified file was not found at that location therefore could not be deleted. The name of the element or list of elements will follow this message, so name the elements properly. In case you apply the behavior multiple times using the same form it will be no use to change the message for each one, the last encountered will be displayed.
Redirect To: If the file is found and deleted you may redirect to another page, but if you do multiple delete it is recommended to apply a redirect on the last that will be executed and if a Delete Record is performed it will happen after file deletion. In other words apply a redirect always after the last operation unless you have other need.

A simple example

Assume a user was registered and uploaded its picture, now he wants to delete his record and delete the picture.
Create the recordset which will retrieve only his data, create a form which may just have only 2 hidden fields and a delete button. Other references may be displayed on the page. Bind the picture url source on one hidden fields and the user identification source on the other hidden field.
Open the behavior and select the form we are using and the element which contains the file url, if this is a complete relative path we can ignore the Aux Path otherwise use it to define the missing part of the path.
Insert the message for the case the file will not be found and click Ok.

Apply the Delete Record using the hidden element which contains the user id and here define also the page to redirect after all operations are done.


by FELIXONE