Xojo Desktop FolderItem Not Working on Mac

The following code works in Windows, but not on the Mac:

If lstFiles.SelectedRowIndex > -1 Then
  Var file As String
  file = txtImageFolderIn.Text + lstFiles.SelectedRowValue
  Var fileItem As New FolderItem(file)
  If fileItem <> Nil And fileItem.Exists Then
    Var pictPhoto As Picture = Picture.Open(fileItem)
	// More code here.
  End If
End If

txtImageFolderIn contains the folder path and lstFiles contains a list of .jpg image files.

For some reason, the fileItem is assigned, but the Exists property is false. I have no idea why. Obviously, the Picture.Open call will not work if the fileItem is considered non-existent.

Please note that I’m a Windows developer trying to become a Windows/Mac cross-platform developer, which means I’m new at both Xojo and Mac. If there is something obvious that Mac users know, please explain.

Any help would be appreciated.

1 Like

On Mac you can’t just assume you have access to any path. You have to be given a FolderItem by a user action like an Open/Save dialog or a drag & drop file action.

There are some locations you do have permission to access all the time, but constructing a FolderItem from a path doesn’t always work.

What locations have permission to access all the time? Is there a way to make selecting a file from a list work?

  1. You can assume permission to SpecialFolder.Temporary (usually through FolderItem.TemporaryFile and SpecialFolder.ApplicationData.Child("my.bundle.identifier")
  2. Store the actual FolderItem as the RowTag when you fill the Listbox, you’ll then be able to retrieve it later and you’ll still have permission to access it

Excellent! I’ll try this later and report back.

That worked perfectly! Thank you!!!