Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to check file type 1

Status
Not open for further replies.

Bhashi

Programmer
Sep 13, 2022
15
LK

I used Getfile() file function to get Excel file when I click button

Code:
[b]X[/b] = Getfile('xls', 'Please Select The XL File ', 'Browse')
I want to know how to check if uploaded X's file type is one of the below.
(*.xls, *.xlsx, *.xlsm, *.xlsb)
 
First take a look at the cFileetensions parameter description in the help, you can offer the dialog to initialize with all these options for the user: X=Getfile('xls,xlsx,xlsm,xlsb',...)

And then after the selection you can get the file extension of the selected file with JUSTEXT(X). Take a look at the whole family of JUST...().

Chriss
 
Something like this:

Code:
X = Getfile('xls', 'Please Select The XL File ', 'Browse') 
IF NOT EMPTY(X)
  IF INLIST(UPPER(JUSTEXT(X)), "XLS", "XLSX", "XLSM", "XLSB"))
    * File type OK
  ELSE
    * Not OK
  ENDIF
ELSE
  * User cancelled
ENDIF

[highlight #FCE94F]EDIT: There was a syntax error in my INLIST() above. Now corrected. Apologies.

Mike[/highlight]

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
As things stand, your GETFILE() will only display those files whose extension is XLS - not XLSX, etc. The user will still be able to select "All files (*.*)" under "Files of Type" but they might not know they need to do that. A better option might be:

[tt]GETFILE("XLS, XLSX, XLSM, XLSB")[/tt]

But you would still need to check that they have selected the right file type. Modifying GETFILE() in this way only alters the files they see; it does not prevent them from selecting other files.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top