Keeping a document open

How do I keep a document open for writing? When my method ends, the binary stream is closed even without a close statement. I need to keep the file open for writing so that other applications cannot access the document while my app is running. Thanks --Will

Probably you opened the binairy stream inside the method, which makes it scope only withing that method. From the moment you end your method the binary stream is also closed. You can make a global folderitem and binary stream and then your document will remain open as long as your application is running.


Thanks, Chris! I tried making the binary stream a window property, as each window will hold a different file for editing I cannot make it global to the app.

When I place the binary stream into a window property, and the FolderItem into a window property, the app does keep the binary stream open, ( if I try to open another binary stream on the FolderItem the App crashes). Even with the binary stream open the Finder will still allow the file to be deleted.

In addition to this problem, it it possible to keep up with a user moving the document while it is open in my app? Right now if I move or delete the document, a new one appears in the original position when I press save in my app.

Thanks. —Will

How do you save your folderitem? Don’t save the path to the folderitem but the SaveInfo:


The choixe was to create a BinaryStream Property in a Module or App.

For the other problem (the Finder allows to delete the file): place the file in a system folder for example (Application Data).

Your other solution is to close the BinaryStream, and Lock the file (using FolderItem.Locked = True). But you will have to unlock it before you try to write.

And in the end, you will never disallow a user to delete it (in a way or in another): once you application quits, (s)he can delete the file.

Thank you all. With further experimentation, I discovered that MS Word has the same problem. Evidently MacOSX will allow deletion of open files, unlike MacOS9 and back. I’ll have to live with it :). -Will

I forgot to note that even if the Finder allows to delete a Locked file, a warning is issued to warn the user about what (s)he is doing.

But this change nothing: the user is able to delete a locked file. The base assumption is the user is master of his computer. A choice.

That said, as an user, even with three successive warnings, I am capable of doing wrong thing (gothere, done that with an Apple II in the 80s…)