From Xojo Documentation
Supported PlatformsProject Types: Desktop Platforms: macOS, Windows, Linux
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 file types in your project, 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 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.
You can also pass in actual FileType names; they are converted to their corresponding strings.
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 opens an mp4 file and then opens its movie and assigns it to a MoviePlayer control. The file type was added using the File Types Editor as a custom Common File Type.
Dim m As New Movie
f = GetOpenFolderItem("video/mp4")
If f<> Nil Then
m = f.OpenResourceMovie(1)
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.
jpegType.Name = "image/jpeg"
jpegType.MacType = "JPEG"
jpegType.Extensions = "jpg;jpeg"
Dim pngType As New FileType
pngType.Name = "image/png"
pngType.MacType = "PNG "
pngType.Extensions = "png"
Dim f As FolderItem
// The actual FileTypes are converted to strings automatically for use
// with GetOpenFolderItem
f = GetOpenFolderItem( jpegType + pngType )
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.
f = GetOpenFolderItem(FileTypes1.VideoXMsWmv) // Converts FileType1.VideoXMsWmv to a string
If f <> Nil Then
MoviePlayer1.Movie = f.OpenAsMovie