Launch won't work first time.

I store pdf documents as blobs in an sqlite database. This works fine. When I want to see one, I click a button which pulls it out of the database, writes it to disk as a temporary file, and then launch it thus:

f = GetTemporaryFolderItem f.Name = f.Name + "temp.pdf" if f.Exists then f.Delete b=BinaryStream.Create(f) b.Write rs.Field("pdfocument").NativeValue b.Close rs.Close f.Launch

Now here’s the problem: the first time I click on the button that does all this… nothing happens; the second time (and all subsequent times) it works fine.

I’m on a Mac using Preview as the pdf viewer.

I would say its a matter of timing… just because you said “close” doesn’t mean that operation is complete, and the file may still be buffering for a few milliseconds when it tries to launch.

What are you doing with name property?
Please use child() function!

The buffering sounds plausible. The pdf files are only around 50Kb. Any idea how to avoid this? It’s just a nuisance, not a fatal flaw!

Why use child()? I like to keep things simple, and this code works :slight_smile:

Thank you for your replies.

But you mess up the folderitem and I wonder if child function makeshift work!

I am intrigued to know how I am messing up the folderitem and how the child function could be useful in this context.

f = GetTemporaryFolderItem
f.Name = f.Name + "temp.pdf"

returns a screwed up folderitem as there is no separator before “temp.pdf”
the proper method would be

f = GetTemporaryFolderItem.child("temp.pdf")

put a MSGBOX after your 2nd line and you will see what I’m talking about.

another reason to use child is when you are specifying root path, is that ending the path in \ or not will make a difference.

as an example if I use root folder + file object, I could get:

c:\tempfile.txt
vs
c:\temp\file.txt

by using child, it ensure the child object always goes into the root folder you are calling.

Not much success with GetTemporaryFolderItem but just using

f = GetFolderItem("").child("temp.pdf")

got rid of all the problems, including the buffering issue.

Thank you all for your help.

Try a b.flush before the b.close

Failing that try immediately opening the file again after the close and see if you encounter an issue if not close that second open and try the launch and see if the problem persists.