Accessing the local file sytem from Lotusscript

Quite a while ago I had to create an interactive online help for a Lotus Notes application where various multimedia files had to be made available on a local disk drive to be displayed in the browser interface.
Since innovative concepts require unusual ideas we decided to deliver these files via the same Lotus Notes application in putting them into a profile document and ‘unpack’ them to a local disk drive once required.
On of the necessary functionalities to accomplish this had been the transfer of a file onto the local file system. This article describes the LotusScript functions used to achieve this.

First of all I needed access to the profile document where the multimedia files had been stored within the database.

Dim s As NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim Doc As NotesDocument
Dim rtitem As NotesRichTextItem

Set s = New NotesSession
Set db = s.CurrentDatabase
Set view = db.GetView ("(Configuration)")
Set doc = view.GetFirstDocument

The multimedia help files will be stored within the local Notes data directory to be displayed. The environment variable ‘Directory’ within the notes.ini does contain this path and can be accessed using the GetEnvironmentString method of the NotesSession class.
The application name has been stored in the profile document allowing this code to be a bit more reusable.

Dim FileName As String
Dim DataPath As String
Dim ApplicationName As String

ApplicationName = doc.applName(0)
DataPath = s.GetEnvironmentString("Directory", True) & "\Help\" & ApplicationName

Once we know the desired path for the help files to be stored a new directory can be created using the Lotusscript Mkdir statement.

Mkdir DataPath

All files have been attached to the richtext field “HelpFile” within the profile document. After accessing the richtext object of the document class we are able to iterate through the array of embedded objects and save each individual file to the defined path on the local hard drive using the extractFile function of the NotesEmbessedObject class.

Set rtitem = doc.GetFirstItem ("HelpFiles")
If (rtitem.type = RICHTEXT) Then
Forall o In rtitem.EmbeddedObjects
FileName = o.Name
o.extractFile(DataPath & "\" & FileName)
End Forall
End If

There are some comments I have add to the functionality described above:
First of all – the code does not include any error handling for the ease of demonstration. I guess there is no need to mention that poor or even non-existing error handling is a bat habit, which can end up with frustrated users or lost jobs/contracts.
Unfortunately LotusScript did not have the native ability to handle compressed files. Writing the same function in Java would actually have the advantage of being able to store the files into a Zip or Jar archive.

Leave a Reply

Your email address will not be published. Required fields are marked *