From Xojo Documentation
Jump to: navigation, search

Class (inherits from Object)

Specifies types of files for use by your application.

Dynamically created File Types do not have access to all the properties that are available for File Types created in the File Types Set Editor.

Extensions MacCreator Name
Icon ReadOnlyProperty.png MacType UTI

File Type Set Properties
All ReadOnlyProperty.png


You can use the FileType class to dynamically create file types. Not all properties are available. Specifically, you cannot use All, UTI or Icon.

The FileType class has a built-in conversion to String. This enables you to use a FileType object anywhere you would normally use a String to indicate the file type. It also has built-in addition operators that let you add two FileTypes, or a FileType and a String, to get a String. The result is the name of the FileType joined with the other one (or the String) with a semicolon. This is the format required by functions like GetOpenFolderItem. These built-in operators make it possible to work with FileType objects as if they were strings. The example illustrates the operators. You can, of course, specify the file type as a string by passing its name.

File Type Sets

In the File Types Set Editor, each file type is shown as one row in the list. A File Type Set created in the File Types Set Editor has the String property All that returns all of the file types in the set. Use All instead of multiple file types when you want to refer to the group of file types. Suppose you create a File Type Set called ImageTypes in which you specify all of the valid image types that your application can open. You can specify the entire list of image types with a line such as:

f = GetOpenFolderItem(ImageTypes.All)

An advantage of using All is that you can modify the members of the ImageTypes set and you won't need to update your code. Otherwise you would have to add each individual file type together to get the entire set:

f = GetOpenFolderItem(ImageTypes.JPEG + ImageTypes.MacPICT)

(This assumes that the file types JPEG and MacPICT are the members of the ImageTypes set)


The following example dynamically creates two FileTypes, one for JPEG files and one for PNG files. You must provide values for the MacType and Extensions properties. It then displays an Open File dialog box that allows the selection of only those two file types.

Dim jpegType As New FileType
jpegType.Name = "image/jpeg"
jpegType.MacType = "JPEG"
jpegType.MacCreator = "prvw"
jpegType.Extensions = "jpg;jpeg"

Dim pngType As New FileType
pngType.Name = "image/png"
pngType.MacType = "PNG "
pngType.MacCreator = "ogle"
pngType.Extensions = "png"

Dim f As FolderItem

//using the addition and conversion operators...
f = GetOpenFolderItem( jpegType + pngType )

To specify the Display Name using a constant, set the name property equal to the name of the constant. In the following example a global constant, kMyPNGType, has been created in a module.

Dim pngType As New FileType
pngType.Name = kMyPNGType //name of a constant
pngType.MacType = "PNG "
pngType.MacCreator = "ogle"
pngType.Extensions = "png"

Dim f As FolderItem

f = GetOpenFolderItem(pngType)

See Also

FolderItem, FolderItemDialog, GetOpenFolderItem, GetSaveFolderItem, OpenDialog, SaveAsDialog classes.

Personal tools

Starting Out
Dig Deeper
More Help