FolderItem.Open problem (with pdf)

I have a listbox containing the names of pdf files in one of the columns. The user needs to open one of these when running the app. There are about 150 rows, so 150 different pdf files. All are in the same location.

The majority of the files open ok as expected, but there are about 25 which do not open, even though they are there, and open ok from Finder with my default pdf reader (Adobe Reader).

When a file fails to open, I get this IO Exception:

The application “[correct filename here].pdf” could not be launched because a miscellaneous error occurred (OSStatus -36).

The code which opens the pdf file is this, in a separate Method:

Var ns as String
ns = str(StartWin.TitlesLB.cellvalueat(StartWin.TitlesLB.selectedrowindex,3)) 'pdf
Var pdf as FolderItem = Specialfolder.Desktop.child(“Xojo Projects”).child(“HPC Mk 2 with DB”).child("[subfolder for the pdf files]").child(ns)
if (pdf.Exists) AND (pdf <> nil) then
End If

I wonder if anyone can point me in the right direction to solve this? I wonder about that Miscellaneous Error!

Thanks in advance

Cascading Childs is a bad idea. Try to use one child per line and check for error all along.
Better: create a FolderItem to reference the holding folder, check if it is valid / exists, then from that reference load each pdf using Child.

Now, what about the contents of the 25 pdf (vs the others) ? Size of each of the 25 files (vs the others).

Try to run the program and open one of the 25 first…

1 Like

Karen A had a similar problem with html files, this sounds similar. Open a terminal and try doing “chmod -x [correct filename here].pdf” on one of the files and then see if you can open it. See feedback 64706.

The description for OSError -36 is

The Finder can’t complete the operation because some data in “FileName” can’t be read or written.

Make sure the user and read permissions on the file are correct and match the others that work.

Thanks Emile for your help.

I have removed the Children (!) so that I now have

Var pdf as FolderItem = Specialfolder.Desktop.child(“Xojo Projects”).child(ns)

I copied 2 pdfs (1 working & 1 not) to the Xojo Projects folder, but this did not help. The same one failed with the same error.

All the pdfs are moderate size - all less than 100MB and some < 1MB. I have not thought to analyse whether there is a relationship between the failing files and their size.

I have also checked permissions, using right-click / info in Finder, as suggested by Greg. All are the same.

I have not tried Bill’s suggestion - I don’t use Terminal much I’m afraid!! Perhaps I should.

This one is easy. Open the terminal and also a finder window with a problematic pdf file in it. In the terminal, type "chmod -x " (note the space after the x), and then drag a single pdf file into the terminal window. That will copy the full path to the end of the chmod line so it will look like “chmod -x /Users/You/Full/Path/To/theproblematic.pdf”. Then type return in the terminal and that will execute it.

Thank you so much Bill, that’s really clear and helpful, and it is working - I haven’t done all the files yet, but every one that I have done opens correctly.

I’m not sure that I fully understand chmod, but I’m working on that!

The only problem with relying on this is if something happens on one of your user’s machines, and having to explain it to them. Karen said she noticed this behavior was a change between 2019R1.1 and 2021r1.1 - 2019 will open the file, 2021 won’t.

Thanks Bill - really helpful!

I have now used chmod on all the files and they al work ok - so that’s great.

I think my problem may be related to Karen’s, which you describe, as I have an earlier version of my app which was created quite some time ago and certainly before I installed Xojo 2021. I now have Xojo 2021R1.1 . I never had this problem with that earlier version of the app, even though the pdf files being opened were the same (though I am now using copies made with Finder, in a different folder).

I don’t know if I can check which version of Xojo was used to create the earlier version of my app, or if it would be useful for anyone to know this.

Can’t the app itself use chmod using a shell so the user doesn’t have to even know about the issue? Wouldn’t it work?

1 Like
Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.