Class

FileType


Description

Specifies types of files for use by your application.

Properties

Name

Type

Read-Only

Shared

All

String

Extensions

String

Icon

Picture

Name

String

UTI

String

Methods

Name

Parameters

Returns

Shared

ConformsTo

String

Imported

Boolean

MIMEType

String

Property descriptions


FileType.All

All As String

This property is read-only.


FileType.Extensions

Extensions As String

The file extension for the file type, or several extensions separated by semicolons, e.g., "jpg;jpeg". A period before the file type is required on Windows, but is optional on other platforms.

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

Var jpegType As New FileType
jpegType.Name = "image/jpeg"

jpegType.Extensions = "jpg;jpeg"

Var pngType As New FileType
pngType.Name = "image/png"
pngType.Extensions = ".png"

FileType.Icon

Icon As Picture

The icon associated with the file type.

This property is read-only.


FileType.Name

Name As String

The MIME name used to refer to the File Type in your code.

This is what is shown in some open/save file dialogs. The Name property can be specified by a constant. When using dynamic constants, the names are automatically localized on macOS. On other platforms, the Name property will return the dynamic constant value, which allows you to register/update your file type with the system using the localized name.

You can see a list of common MIME names by opening the File Type Group Editor and choosing the command bar button to add a common file type. The menu will show some common types and you can click "More.." to open a chooser at the bottom that shows many more.

The following defines the jpeg file type in code:

Var jpegType As New FileType
jpegType.Name = "image/jpeg"
jpegType.Extensions = "jpg;jpeg"

FileType.UTI

UTI As String

Uniform Type Indicator used by macOS for opening files. Can only be set in the File Types Set Editor.

Read about UTI on Wikipedia.

Method descriptions


FileType.ConformsTo

ConformsTo As String

Returns a comma-delimited list of UTIs to which the file type conforms. These UTIs represent the parent categories to which your custom file type belongs.


FileType.Imported

Imported As Boolean

If True, this File Type is one defined by another company or organization.


FileType.MIMEType

MIMEType As String

The MIME type associated with the file type.


Notes

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.

You can use the FileType class to dynamically create file types, although 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. 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 FolderItem.ShowOpenFileDialog. 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 = FolderItem.ShowOpenFileDialog(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 = FolderItem.ShowOpenFileDialog(ImageTypes.JPEG + ImageTypes.PNG)

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

Sample code

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

Var jpegType As New FileType
jpegType.Name = "image/jpeg"
jpegType.Extensions = "jpg;jpeg"

Var pngType As New FileType
pngType.Name = "image/png"
pngType.Extensions = "png"

Var f As FolderItem

' Use the addition and conversion operators to combine the file types
f= FolderItem.ShowOpenFileDialog(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.

Var pngType As New FileType
pngType.Name = kMyPNGType ' name of a constant
pngType.Extensions = "png"

Var f As FolderItem

f = FolderItem.ShowOpenFileDialog(pngType)

Compatibility

All project types on all supported operating systems.