Open dialog in a specific directory

The Xojo Documentation had sample codes to get me to the Documents Directory. I need to have the file open dialog open in a specific directory in windows documents called User Files. How do I rewrite this to get to work?

[code]Dim f As FolderItem
dlg As New OpenDialog

//dlg.InitialDirectory = “\Users\Public\Documents\AppName\User Files” // <- Doesn’t work
dlg.InitialDirectory = SpecialFolder.Documents // <- gets to documents directory

dlg.Title = “Open User Database”

f = dlg.ShowModal()
[/code]

InitialDirectory is a FolderItem so provide it with the one you want.

Start with a SpecialFolder location and use the .Child and .Parent functions of FolderItem to navigate around, but beware it’s an automatic lock-in you’ll get a RuntimeException if it’s more than one-level of not-found. Wrap it in a try-catch and have a default fallback.

Hey Tim

Without Try Catch would this be right

[code]//" Users\Public\Documents\AppName\User Files"

f = GetFolderItem(“Documents”).Child(AppName").Child(“User Files”)

dlg.InitialDirectory(f)[/code]

f = SpecialFolder.Documents.Child(“AppName”).Child(“UserFile”)

The method GetFolderItem starts next to the executable, so unless your user keeps the exe in the Public folder I don’t think that’s the path you want.

The path Users\\Public\\Documents is a shared folder, which most users will not have write access to, so keep that in mind. According to the documentation it’s SpecialFolder.SharedDocuments

So to make the path you mentioned it would be SpecialFolder.SharedDocuments.Child("AppName").Child("User Files")

(I try to teach a little instead of just handing out code)

Thanks Roger that worked.

f = SpecialFolder.Documents.Child("AppName").Child("User File")

dlg.InitialDirectory = f

f = dlg.ShowModal()

Please tell me you realize that’s a different location than you had originally asked for.

On macOS, it looks like users can have read/write access to files inside this - though I’ve had various reports that some users can’t…

Why wouldn’t users have write access to this? Is there a dedicated place where all users of the computer can store files for each other to use?

I am trying to find a place to store document template files that no matter who logs onto the computer, they can get to those templates, creating, reading, writing, and deleting.