Opening a file next to one selected by the user

My app imports data from dBase / FoxPro files and I’ve run into a problem. Sometimes these database tables consist of two separate files. First the .DBF and secondly a .DBT or .FPT file. The problem I’ve run into is I think related to Apples security system.

– I present an open file dialog
– the user chooses the .DBF file.
– I open the file and then check of the .DBT or .FPT
– I then attempt to open the second file and I get an IOException with a number of 1.

The reason I suspect it is Apple security is, if I try and open the .DBT file manually in the app and then try the process again it actually works. Is there anything I can do to trigger the “Application would like to access files in folder xxx” message. I would rather not have to present two file open dialogs to get at the second file.

The App is destined for the Apple App store so I may not have much choice in the matter.

The App isn’t signed yet, but this is also happening in the debugger.

You are correct, this is a violation of security protocols. Originally it only happened with the App Sandbox.

You can try signing the application as Apple do treat unsigned apps differently than signed apps. If it works while signed (but no App Sandbox) you can still release your application outside of the App Store. Right now a growing number of developers are abandoning the Mac App Store, so don’t feel bad. All of my popular apps are prohibited from being in the App Store.

However, to solve the problem, I think the clearest way to explain to the user is to provide a dialog with a couple of fields. Clicking “Select” next to each field allows the user to choose the correct type of file.

iIRC there is supposed to be a way using newer file providers, but I’ve not explored that route,.so I can’t really comment.

Thanks, I thought so. I’ve implemented a check of the file and open another file picker when required. It clears the problem and things now work normally. I’ve built it to automatically select the file so all the user has to do is press Open once more.

Thanks for the help.

1 Like

I’d also recommend setting the description of the second file dialog, if you haven’t already, to explain why they need to select the second file.

That was sorta the reasoning behind having a dialog where they then choose each file separately, because it makes it clear that they have to select two files to start with, rather then the customer selecting a file and then suddenly getting a secondary file selection dialog.

Yes, I’ve set the description explaining why and what they need to do. I don’t really want to put a specific file dialog for this as I’m allowing import of a series of file types through an import menu item. Until they pick a DBF I don’t know that’s what they are going to do. I think my model now fits the need, however, the text is waiting review and improvement.

Not all DBF files have a memo file so it is only required some of the time.

Dumb question, is asking for the parent folder against the rules? That way you’d only have to ask once.

The user chooses File Import and opens a file. It could be xlsx, csv, txt, dif or dbf.

If it is dbf there may or may not be a dbt or fpt file to go with it. If there is I have to get it opened. I can use code to navigate the correct path for the file, see if it is there and then ask for permission to open it. It is a one time event as the table is then loaded into my application use it for analysis etc.

Asking for permission for the folder feels suspicious and won’t help for the one file I need to open this time. The next time they do this sort of thing it could be a completely different folder.

Thanks for the suggestions.

It is possible that when the app is finished and signed I will need to set entitlements for it. It would need to be able to access files in the documents folder. I think that is an entitlement (I could be wrong) but it is possible that would solve the problem.

The folder can contain multiple database files, if you ask for the folder to get permissions, you will need a second dialog to choose the database.

Why not, if there’s a .dbf file, construct the corresponding name for the .dbt or .fpt, and if they are there just open them?

That’s exactly what I was doing. However, I started getting IOErrors (1) when opening the file. If I tried choosing the file via a file open dialog and then doing the exact same thing it would work. Without that it would always fail

Well I’ll be hornswoggled!

Gosh sounds painful :wink: