Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Validating A File's Type
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00436540
Message ID:
00436542
Views:
27
>If I allow the user to select a file using GETFILE(), how can I
>validate that the file ther user selected really IS the correct
>type of file?
>
>For example, if I use:
>
>
>cFileName = GETFILE("doc")
>

>
>
>how can I be sure that the user selected a Word document?

I don't know that you can.
Windows associates certain file types by file extension - which means you can give an Excel file a .DOC extension and Windows will attempt to open it with Word (e.g.). That may or may not be successful.

The best you may be able to do is confirm that the file they selected has the extension you gave to GETFILE(), e.g.
lcExt = "doc"
lcFileName = GETFILE(lcExt)
IF !UPPER(JUSTEXT(lcFileName))==UPPER(lcExt)
  ** error
ENDIF
note: JUSTEXT() is in Foxtools.fll if you're not using VFP 6.0 or later.

You could also use the FileSystemObject and get the file Type and check that, e.g.
oFSO = CREATEOBJECT("Scripting.FileSystemObject")
oFile = oFSO.GetFile(GETFILE("doc"))
IF oFile.Type # "Microsoft Word Document"
  ** error
ENDIF
Insanity: Doing the same thing over and over and expecting different results.
Previous
Reply
Map
View

Click here to load this message in the networking platform