This is a class to drag/drop files from windows explorer and link it to a record in our database.

The class is an image with a folder icon. You first assign it with a Key ID. This is the id that will link to the record. So if you want to open files attached to Client with ID=100, you could make the Key ID = 'CLIENT100'.

The class can also be made invisible and used as an helper class to add files. Eg. adding a picture to an employee record.

The class has properties

1. KeyValue - this is the ID for the files. eg. CLIENT100

2. ReadOnly - Set this to .T. if you only want to view

3. SaveLocation - Files dropped into the form are copied to subfolders created in this location. Give the UNC path and not the mapped path of the server here. eg \\MyServer\MyShare\Documents

4. TableAlias - Information about files dropped in has be stored in a DBF table. You will have to open it and buffer it. Give the alias of the table here. The file can be created with
create table YourDBFName (ID int AUTOINC,DOCID Char(20),FILENAME Char(254),SAVEDNAME Char(20),SAVEDDIR Char(254))
Make sure DOCID is large enough to take all sizes of your KeyValue.
Make ID your primary key
Also index on DOCID so don't make it too large.

5. Title - Title of the form that will be opened

Methods of the class are

1. AddFile - To add a file to the current KeyValue. Should be used when it is an helper class

2. DeleteFile - To delete file by ID

3. GetFileByNumber - Returns an object with ID, FileName as saved, The original file name when it was dropped.

4. GetFolder - Returns the folder where files can be saved. Will be a subfolder of the SaveLocation folder above. If there are more than 1000 files in the current subfolder, a new subfolder will be created

5. GetNumberOfFiles - Returns number of files for a record

6. ShowDocuments - Shows the form where files can be dropped. Will also show list of files which can be opened by double clicking.

There is a sample form along with the enclosed class.

The sample uses the supplier table of the tastrade.

It has 2 instances of the document class.

One is the normal visible and you can add documents to each supplier by clicking on it.

The second is a helper class that controls the image against each supplier. You can click on the image and choose a JPG

Most of the code is in the click of Image1 and in the afterRowColChange of the grid. The rest of the code is taken care of by the document class.

The code requires SYSTEM.APP for GDI+ to get the associated icons. You can get SYSTEM.APP from

Leave a Reply

Your email address will not be published. Required fields are marked *