Web Applications - File Import Feature Pack

To purchase this Feature Pack, please click here.


Watch Video - Part 1

Watch Video - Part 2

Watch Video - Part 3


The File Import Feature Pack allows you to add a button to a Grid component that will upload a file from the user's machine to the server and then import the data in the uploaded file.

The following types of files can be uploaded:

The data in the uploaded file can be imported into:

How to Add Import Functionality to Your Grid Component

To add the Import function to a Grid, create a new button by placing a button object in the list of Grid or Detail View controls, or by using the Action Buttons Feature Pack. Then define the action for the button. You will see that the list of available actions in Action Javascript will include a new action: Import Data



When you select the Import Data action, the builder is opened:





Honor Grid Rules and Events vs. Bulk Import

When the data is imported into the table that the Grid is based on, you can specify if you want to perform a fast import, or if you want to honor the Grid rules and events.

If you choose to honor the Grid rules and events, then the data validation events that you have defined are honored, and the CanInsertRecord event is fired for each row that is imported. In effect, it is as is you were entering the records into the grid manually, one record at a time.

Compared with a bulk-import, this will be very slow and is only appropriate for files that contain a few records. Otherwise, you will put a significant strain on your server, impacting the response times of other users.

On the other hand, if you choose not to honor Grid rules and events, you can import thousands of records at a time.

If you do not turn on the honor Grid rules property, you still have the option of validating the data before it is imported. See 'Server-side Data Validation' below.



Server-side Data Validation

After you have uploaded the file to the server, but before the data is actually imported into the target table, you can validate the data. In order to validate the data, specify the name of the Xbasic function  you want to call in the 'Data validation Xbasic function'. You can then press the hyperlink to get a function prototype for the validation function.

The validation function gets passed an object (called 'e') that contains the name of the temporary file on the server where the data in the uploaded file exists.

This temporary file is a native Alpha Five table. You can write Xbasic code to loop over the records in this temporary table. Your function can modify data, add records, or delete records. When your function is done, it should close the temporary table and then Alpha Five will proceed to import the data.

If your function sets e.abort = .t. then the Import is aborted and the error message set in e.errorText is displayed to the user.

Here is a sample validation function that deletes any record where the quantity is > 10. If for example, the user uploaded a file with 20 records, and 3 records were deleted, then only 17 records will get imported into the target table.


function MyValidateFunction as v (e as p)

dim t as p

t = table.open(e.inputFilename)

'If you turn on batch begin, scripts that loop over records in a table are significantly faster


dim i as n

dim count as n

count = t.records_get()

for i = 1 to count

    if t.quantity > 10 then




        'After deleting a record, the record pointer automatically moves to the next record.

        'So, no need to advance the record pointer!



    end if

next i


'Call batch end



end function

Debugging your Server-side Data Validation Event

Because the Import Feature Pack works in Working Preview, you can easily debug you data validation code by putting


into the function and then running the Grid in Working Preview mode.