FileType and FileTypeGroups define types of files that an application may wish to open or save. They are not for individual files on disk. You can use them in File Open and Save dialogs to filter the types of file it will allow you to work with.
The FileTypeGroup editor allows more properties than you specify. Including making drag and drop file opening possibilities on macOS.
I haven’t seen a UTI being required for the Filter of an Open or Save dialog. I only ever define a Name and Extensions. You may see success omitting the UTI?
Wow, this is a great tip Greg that I was unaware of. I guess you learn something new everyday.
I’ve never seen this anywhere in the documentation but maybe I missed it. Anyone aware of this being documented somewhere? If not, I’ll place a ticket to get things updated.
Add a FileTypeGroup to your project. Click on it and open the editor. Drag and drop an existing file to the editor, it will fill in the data required. Then use the GroupName and FileType name, as shown above. It should work.
Var oFileDialog As New SaveFileDialog
oFileDialog.InitialFolder = oFile.Parent
oFileDialog.Filter = ExternalFileTypes.ExcelXLSX + ExternalFileTypes.TXTFile + ExternalFileTypes.CSVFile + ExternalFileTypes.DBFFile + ExternalFileTypes.OXDFile + ExternalFileTypes.DIFFile
oFileDialog.SuggestedFileName = DatasetName
oFileDialog.ActionButtonCaption = kButton_Export
oFile = oFileDialog.ShowModal( Me )
Yes, it is, but you need the correct information in there. On Mac it relies on the UTI system, on Windows it’s more the extension. Drag and drop will get you the information you require.
On Mac the FileTypeGroup editor does more than just allows the dialog to work. For example it adds entries to the Info.plist file defining the types of file the app opens, saves etc. It also adds icons to those file types.
UTIs can be tricky, there is a whole tree of them. By declaring ones high in the tree you are including ones below that point. It could be why text files are showing up. There should be a more specific UTI for SQLite files than just “public.database”.
It is important to only put the specific UTI in the Identifier property, the other elements should go in the ConformsTo property.
This explains the structure a little:
There’s a list somewhere with lots of types in it, but I can’t find it.
Var jpegType As New FileType
jpegType.Name = "image/jpeg"
jpegType.Extensions = "jpg;jpeg"
Var dlg As New OpenFileDialog
dlg.Title = "Select a jpeg file"
dlg.Filter = jpegType.Extensions
Var f As FolderItem = dlg.ShowModal
should limit the Open Dialog to only allow Jpeg file extensions, but if you try it, it won’t work.
That is the problem that Emile is finding, by following the Documentation is not getting the wanted results.