Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Microsoft: FoxPro FAQ

Tips -N- Tricks

How can I select multiple files from Windows by ChrisRChamberlain
Posted: 1 Feb 03 (Edited 6 Jan 05)

If you want a user to be able to select multiple files from Windows, create a new form and from the VFP menu :-

Tools > Component Gallery > Foundation Classes > Dialogs > Common Dialog (then right click) > Add to Form

Rename the class to .cusCommonDialog.

As you will discover, there are numerous properties and methods for this class. It combines GETFILE(), PUTFILE() and presents a modern interface to the user.

The following example sets the relevant properties to enable multiple file selection, shows the dialog and displays the path\filename.ext of the selected files in a cursor.

CREA CURS FILENAMES (filename C(254))

WITH THISFORM.cusCommonDialog
&& Clear filters in case in loop
    .lAllowMultiSelect = .T.
&& Enable multiple file selection
    .cFileName = []
&& Do not set an initial file name
    .cInitialDirectory = [C:\My Documents]
&& Start folder
    .cTitlebarText = [Select multiple files]
&& Dialog titlebar text
    .aFilterList[1,1] = [Image Files (bmp,gif,jpg)]
&& First half of filter list
    .aFilterList[1,2] = [*.bmp;*.gif;*.jpg;*.jpeg]
&& Second half of filter list
* Should you want additional filters you can add them with :-
.AddFilter([MS Office (doc,ppt,rtf,txt,wri,xls)],[*.doc;*.ppt;*.rtf;*.txt;*.wri;*.xls])
    .nFileCount = 0
&& Reset file count value in case dialog in DO WHILE... loop
&& Show dialog

    IF .nFileCount > 0
&& File(s) selected
        FOR i = 1 TO ALEN(.aFileNames,1)
&& Loop through array created
            INSERT INTO FILENAMES (filename) VALUES ( ;
                ADDBS(.cFilepath) ;
                + LOWER(.aFileNames[1,i]))
&& Insert path\filename.ext in cursor
        BROW LAST
        MESSAGEBOX([You have not made a selection],16,[No files],2000)

If you have OLE drag 'n drop enabled on a form control, you can also drag and drop multiple files from the Windows Common dialog onto your VFP control.

You then need to ensure that you release the Windows Common dialog in the
.OLEDragDrop() event of the VFP control to avoid a recursive call to the Windows Common dialog.

Put the following code into the .OLEDragDrop() event:-

    STRING cNull,;
    STRING cWinName

    LONG hWnd ,;
    LONG wMsg ,;
    LONG wParam ,;
    LONG lParam

lcWindowTitle = ALLTRIM(THISFORM.cusCommonDialog.cTitleBarText)
IF lcWindowTitle = [Select multiple files]

    ** If the file was 'dropped' by the Windows Common Dialog box, close that dialog.

    lnHWnd = FindWindow(NULL,lcWindowTitle)
    IF lnHWnd # 0

There is far more depth to this class than can be demonstrated in a single FAQ - get coding and have fun!

Chris R. Chamberlain

Back to Microsoft: FoxPro FAQ Index
Back to Microsoft: FoxPro Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close