Caution: remove database file in local temp folders

Wednesday, January 6, 2016 7:14 AM UTC

You may know the behavior of Domino when you remove a database in a folder beneath the data folder. If it was the last database file in that folder Domino will automacially remove the folder, too.

Did you know that this also will happen even if you remove a database that was prior referenced from a folder outside of the data folder structure? I didn't!

Use case: if you temporarily extract - let's say -  an attachment from a document that is actually a NSF or NTF to a local temp folder like c:\temp you are able to use the object like any other database in your code, e.g. to create a copy in the server's data folder. If you remove the first database object and the file was the last file in the temp folder Domino will also delete the folder itself! This will cause in unexpected results of the whole system because you may get lost of the system temp folder.

Sample code

Database template = session.getDatabase("", "c:\temp\foobar.ntf");

Database db = template.createFromTemplate("YourServer", "folder/newfile.nsf", false);

template.remove(); // <-- this must be used to remove the file

Actually you want to remove the temporary NSF from the folder but you can't do it with the File.delete() method as Domino still has a handle on the file even if you recycle the original object (in this case template). So you are forced to use the remove method.

Workaround

To make sure the temp folder isn't removed by Domino just put a dummy file inside. The removed NSF isn't the last one so Domino let's your folder alone.





Latest comments to this post

René Winkelmeyer wrote on 06.01.2016, 08:36

It's a good practice to use Notes/Dominos own temp folder for anything temporary. That one is maintained automagically. Using any System folder directly is never good.

 Link to this comment

Leave a comment right here