File Attachments control code

This example provides description of how to use control File Attachments – that means how to add one to a form and also coding capabilities of the control.

1. Create a new form (follow the previous example up to step V. to do that or just add a new form to an existing project).

2. Drag & drop a File Attachments, two Buttons, a Text Block and a Code Block controls (with default names Attachments1, Button1, Button2, TextBlock1 and NDCode1 respectively) on the form from the Toolbox and configure them so the form should look something like Picture 110.

 Picture – Example 2 – prepared form

3. Let the added controls

4. Click the New Event button so the Event Handler dialog opens.

5. Configure the event handler to handle the Added event of the Attachments1 control :

a) Set the name of the event handler to AttachmentAdded.
b) Select Attachments1 as the target object.
c) Select Added as the event name from the list of events.
d) Click the New button to create a new code holder
e) After the Code Holder editor opens, replace the pre-generated code with the following:

f) Name the code holder AttachmentsCode and click the Commit button to save changes.

6. Create new event handler and configure it:

a) Set the Name to AttachmentRemoved.
b) Select Attachments1 as the target object.
c) Select Removed as the event name from the list of events.
d) Type or select value AttachmentsCode to the Code fragment field.
e) Set value of the Event handler to OnAttachmentRemoved.
f)
Click the Commit button.

7. Create another new event handler an set values of its fields like this:

a) Value of Name to DelButtonClick,
Value of Target object to Button1 (i.e. the “Delete first attachment” button),
b) Value of Event name to Click,
d) Value of Code fragment to AttachmentsCode and
e) Value of Event handler to OnDeleteButtonClicked.
f)
Click the Commit button.

8. Create last new event and fill its fields like this:

a) Value of Name to AddButtonClick,
b) Value of Target object to Button2 (i.e. the “Add attachment” button),
c) Value of Event name to Click,
d) Value of Code fragment to AttachmentsCode and
e) Value of Event handler to OnAddButtonClicked.
f)
Click the Commit button.

9. Completed code block should look like next picture.

 Picture – Example 2 – prepared code block

10. Finally, publish the form template and test in the Form Render.