Pointing to App Folder

I am having trouble in R2 pointing to a folder “Data” where my App is located.

Dim dlg as OpenDialog
Dim d As FolderItem

d = GetFolderItem("")
dlg=New OpenDialog
dlg.InitialFolder = SpecialFolder.CurrentWorkingDirectory.Child(“Data”)

dlg.promptText=“Open File.”

When I open the dialog it ends up at the “Documents” folder??

CurrentWorkingDir is not really useful on macOS

Where is the data folder supposed to be ?

Dont do that.
On Windows or on Mac
Neither are happy about apps amending data files in the same folder as the app.

Create a folder named for your company or software, in the ApplicationData folder, and store/amend your data in that.
That works no matter where people put your app

if the data file really is next to the app then CurrentWorkingDirectoyr is still likely wrong

on macOS you want the location of the app bundle

Dim bundle As Folderitem = app.ExecutableFile.parent.parent.parent

AppData under Windows is an invisible folder (here). I learned that yesterday when I wanted to check if my data were there.

Ok so maybe
dlg.InitialFolder = SpecialFolder.SharedDocuments.Child("")

[quote=459899:@Martin Fitzgibbons]Ok so maybe
dlg.InitialFolder = SpecialFolder.SharedDocuments.Child("")[/quote]
I’m curious why you would put .Child("") on there ?
What makes you think that is needed ?

Sorry meant
dlg.InitialFolder = SpecialFolder.SharedDocuments.Child(“CrosswordWizardData”)

ok that makes MUCH more sense :slight_smile:


And this is almost what i personally do, because (as you say) AppData is hard for users to get to, and I want my customers to be able to get at the data files easily.

I use SpecialFolder.Documents as I want the files to be user-specific

Under Catalina, I am not sure you can access SpecialFolder.Documents silently without asking permission first.

What I do in my apps is to provide a button and File menu option to open a documents folder inside my app subfolder, within AppData.

I think you’re right.
On first run, the user is asked.
of course, if they say ‘no’ at that point, then we get into support issues, as all sorts of things can’t work properly.

I recently had to put this into the Help pages:

[quote]Mac (Catalina) : App reports unable to save or read files
New security measures may stop our app from being able to save files.
To make it work as it should, you may need to tell Catalina to allow access to Documents etc
To do that, open System Preferences/ Security, and choose Full Disk Access
Click the padlock to allow changes, and add our app to the list
Then click the lock again to save changes.[/quote]

(Full disc access is likely to be overkill, but its easier to describe than allowing access to specific individual folders such as Documents & Temp & AppData & Pictures & Downloads…)