If I get a document from the database by LotusScript, how can I know which folder does this document belong to?Thanks a lot!
Subject: RE: Folder and document
As has been discussed here repeatedly, if you enable “folder references” in your database Notes will track this for you and you can use the FolderReferences property to find out the names.
However, this only works if folder references were enabled at the time the document was added to the folders. Also, it has bad effects on performance and on size of documents and database.
If you don’t already have Folder References on and you want to scan thru all the folders and find those that contain references to a particular document, here’s the most efficient way I know:
Use NotesNoteCollection to locate all the folder notes’ Note IDs.
Iterate thru the entries in this collection, as follows:
Use GetDocumentByID to get the design note of the folder.
Look at the $TITLE item of the design note to find out the folder name. If the name contains “|”, use only the part of the name after the last “|”
Use the name to look up the folder with GetView.
Use CreateViewNavFrom to find out whether the folder contains the NotesDocument. NotesViewNavigator.Count > 0 means the document is in the folder.
You could just use the NotesDatabase.Views property to get all the views and then loop thru them looking for folders, but last time I checked that was pretty slow, because accessing a view using its NotesView object refreshes the index of the view – even if all you’re doing is testing the IsFolder property.
If you’re using the mail file, you could read entries from the ($FolderInfo) view instead of using the NotesNoteCollection, but the result is the same. The NotesNoteCollection code should work in any database.