From Xojo Documentation
|You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!|
Used to access a document or application selected by the user via the standard open-file dialog box.
|result||FolderItem||Represents the file that was opened by the user. The result will be Nil if the user clicked the Cancel button.|
|filter||String||Semicolon separated list of file types the user can open.
The file types must be defined as REALbasic file types, either in the IDE in a File Type Set or with the FileType class.
The GetOpenFolderItem function displays the standard open-file dialog box for the platform on which the REALbasic application is running. The FolderItemDialog class has the same purpose but allows for some customization.
The filter parameter is used to limit the types of files that the user can open to one or more of the file types defined via the FileType class or in the File Type Sets Editor in the IDE. The filter is a semicolon separated list of file type names. For example, if you wanted the user to be able to open only text files and postscript files when making a particular call to the GetOpenFolderItem function, you would define two file types using either the File Type Sets Editor or the FileType class. You would then pass "application/text; application/postscript" (or the name you chose) as the filter to the GetOpenFolderItem function.
Only files whose type matches one of the file types passed in the filter will be displayed in the open file dialog box. If you want to display all files, you will need to add a file type to the project that uses "????" as its Mac Type.
The GetOpenFolderItem function returns a FolderItem that represents the file the user selected. You can then use the FolderItem to access various data about the file such as its name, full path, etc. See the FolderItem class for more information.
If the user clicks the Cancel button in the open file dialog box, the FolderItem will be Nil. You can test for this by comparing the FolderItem with the Nil value. Accessing a Nil FolderItem will cause a NilObjectException error.
This example illustrates how to use the FileType class do specify the types of files that can be opened by GetOpenFolderItem. When you define FileType objects, you must specify the MacType and Extensions properties. The call to GetOpenFolderItem can combine several FileTypes in the way the example shows.
In the IDE you can create file types for practically all types using the Common File Types button in the File Type Sets editor. It displays a pop-up menu of the most common types and a "More" button that displays a much larger pop-up. Instead of creating your file types in code, you can use the Common File Types feature to set these properties.
The following example uses the built-in file type for WMV movies to open a WMV file, assign the movie to the Movie property of a MoviePlayer, and plays the movie.