Folder References

Hello,

One of our senior directors in the company want a facility wherein i he goes to All Documents view and select a document , he should know in which folder the document is.

I managed to get hold of Folder Reference property and also enabled Folder reference on the database. Now, this is not working on all the documents . I mean for some it tells me the folder name but for some it does not. As he has “N” number of private folders , it becomes somewhat difficult to trace the document.

Here is the script I’m using for getting the folder name :

Dim session As New NotesSession

Dim db As NotesDatabase

Dim doc As NotesDocument

Set db = session.CurrentDatabase

If(db.FolderReferencesEnabled) Then

Else

Messagebox(“Folder references are not enabled”)

Messagebox(“Enabling folder references”)

db.FolderReferencesEnabled = True

End If

Dim doccoll As NotesDocumentCollection

Set doccoll = db.UnprocessedDocuments

Set doc = doccoll.GetFirstDocument

While Not(doc Is Nothing)

i = 0

Forall FolderReference In doc.FolderReferences

i = i+1

Print i, “”, FolderReference

End Forall

Set doc = doccoll.GetNextDocument(doc)

Wend

Exit Sub

Any help is much appreciated.

Thanks

Tom

Subject: Folder References

Hi Thomas,

I think I’m right in saying that Notes only starts recording folder references on documents which are moved into folders AFTER you have enabled Folder References, regardless of what version you are on. I don’t believe there’s any way of getting this information for documents which were filed away before folder references were enabled.

Edit: I suppose you could write some LS which takes the UNID of the selected document then scans all of the folders in the DB for documents with this UNID but I think that the code would probably be quite slow.

Emily.

Subject: RE: Folder References

HI,

Please tell me how can I enable folder reference on database.

Thanks

Anthony

Subject: RE: Folder References

Hello,

On database postopen , u can include this code to enable Folder References .

Dim session As New NotesSession

Dim currdb As notesdatabase

Set currdb = session.CurrentDatabase

If Not currdb.FolderReferencesEnabled Then

currdb.FolderReferencesEnabled = True

End If

Exit Sub

HTH

Tom

Subject: Enable Folder References for a database

One line of executable code in the PostOpen event of the Database Script suffices:

Sub Postopen(Source As Notesuidatabase)

'Enable Folder References for this database.

Source.Database.FolderReferencesEnabled = True

End Sub

Subject: RE: Folder References

Here’s a solution for this, the script will turn on folder references if it’s off and then iterate through folders in the database, removing documents and then re-adding them to the same folder. It stores the folder name in a “CurrentFolders” field in the doc for reference. It clears out this field each time it runs. It has the capacity to hold multiple values in case the document appears in multiple folders.

Sub Initialize

On Error GoTo oops

Dim session As New NotesSession

Dim db As NotesDatabase

Dim views As Variant

Set db = session.CurrentDatabase

If Not DB.FolderReferencesEnabled Then

	Print "Enabling folder references" 

	DB.FolderReferencesenabled=True

End if 

Dim folderExists As Boolean

Dim folder As notesitem

Dim view As NotesView

Dim doc As notesdocument

views = db.Views

Print "Clearing out previous CurrentFolders values"

ForAll v In views  ' Remove previous CurrentFolders field  

	Set view = db.getview(v.name)

	If view.Isfolder Then 

		Set doc = view.Getfirstdocument()

		While Not (doc Is Nothing)

			Set folder = doc.Getfirstitem("CurrentFolders")

			If Not (folder Is Nothing) Then

				Call folder.Remove()

				Call doc.save(True, False)					

			End If

			Set doc = view.getnextdocument(doc)

		Wend

	End If

End ForAll





ForAll v In views  ' Record the new folder values

	print(  v.Name  )

	Set view = db.getview(v.name)

	If view.Isfolder Then 

		Set doc = view.Getfirstdocument()

		While Not (doc Is Nothing)

			folderExists = False

			Set folder = doc.Getfirstitem("CurrentFolders")

			Call doc.Removefromfolder(v.name)

			Call doc.save(True, False)

			Call doc.Putinfolder(v.name, false)

			If Not (folder Is Nothing) then

			ForAll things In folder.Values

				If things = v.name Then folderExists = true

			End ForAll

			Else

				Set folder = New NotesItem( doc, "CurrentFolders", v.name )

			End if

			If Not folderExists Then folder.Appendtotextlist(v.name)

			Call doc.save(True, False)

			Set doc = view.getnextdocument(doc)

		Wend

	End if

End ForAll

oops:

Print "Error " & Error$ & " on line " & Erl()

End Sub

Subject: Folder References

This functionality is built in with R7. Menu Actions/Folders/Discover Folders.

HTH

Patrick

Subject: RE: Folder References

Hello,

But we are on R6.5.4 and R7 is still distant from us to migrate.

Can you send em the script which is written for “Discover Folders” . Probaly it has the answer for my search.

Thanks

Tom