<div class="meta" robots="noindex">

</div>

Method

# GetOpenFolderItem

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

<div class="warning">

<div class="title">

Warning

</div>

This item was deprecated in version 2019r2. Please use `FolderItem.ShowOpenFileDialog<folderitem.showopenfiledialog>` as a replacement.

</div>

## Description

Prompts the user to select a file using the standard open-file dialog box.

## Usage

*result* = **GetOpenFolderItem**(*filter*)

| Part   | Type                                | Description                                                                                                                           |
|--------|-------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------|
| result | `FolderItem</api/files/folderitem>` | Represents the file that was opened by the user. The *result* will be `Nil</api/language/nil>` if the user clicked the Cancel button. |
| filter | `String</api/data_types/string>`    | Semicolon separated list of file types the user can open.                                                                             |

## Notes

The <span class="title-ref">GetOpenFolderItem</span> function displays the standard open-file dialog box for the platform on which the application is running. The `FolderItemDialog</api/user_interface/desktop/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</api/files/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 <span class="title-ref">GetOpenFolderItem</span> function, you would define two file types using either the File Type Sets Editor or the `FileType</api/files/filetype>` class. You would then pass "application/text; application/postscript" (or the name you chose) as the filter to the <span class="title-ref">GetOpenFolderItem</span> 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 <span class="title-ref">GetOpenFolderItem</span> function returns a `FolderItem</api/files/folderitem>` that represents the file the user selected. You can then use the `FolderItem</api/files/folderitem>` to access various data about the file such as its name, full path, etc. See the `FolderItem</api/files/folderitem>` class for more information.

If the user clicks the Cancel button in the open file dialog box, the `FolderItem</api/files/folderitem>` will be `Nil</api/language/nil>`. You can test for this by comparing the `FolderItem</api/files/folderitem>` with the `Nil</api/language/nil>` value. Accessing a `Nil</api/language/nil>` `FolderItem</api/files/folderitem>` will cause a `NilObjectException</api/exceptions/nilobjectexception>` error.

## Sample code

This code opens an mp4 file and then opens its movie and assigns it to a `MoviePlayer</api/deprecated/movieplayer>` control. The file type was added using the File Types Editor as a custom Common File Type.

``` xojo
Dim f As FolderItem
Dim m As New Movie

f = GetOpenFolderItem("video/mp4")
If f<> Nil Then
  m = f.OpenResourceMovie(1)
Else
  MsgBox("Open failed.")
End If
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

This code illustrates how to use the `FileType</api/files/filetype>` class do specify the types of files that can be opened by <span class="title-ref">GetOpenFolderItem</span>. When you define `FileType</api/files/filetype>` objects, you must specify the MacType and Extensions properties. The call to <span class="title-ref">GetOpenFolderItem</span> can combine several FileTypes in the way the example shows.

``` xojo
Dim jpegType As New FileType
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 code 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.

``` xojo
Dim f As FolderIem
f = GetOpenFolderItem(FileTypes1.VideoXMsWmv) ' Converts FileType1.VideoXMsWmv to a string
If f <> Nil Then
  MoviePlayer1.Movie = f.OpenAsMovie
  MoviePlayer1.Play
End If
```

## Compatibility

All project types on all supported operating systems.

## See also

`FolderItem.ShowSaveFileDialog<folderitem.showsavefiledialog>`, `FolderItem.ShowSelectFolderDialog<folderitem.showselectfolderdialog>` functions; `FileType</api/files/filetype>`, `FolderItem</api/files/folderitem>`, `FolderItemDialog</api/user_interface/desktop/folderitemdialog>`, `OpenFileDialog</api/user_interface/desktop/openfiledialog>`.
