0
votes

I want to access and use shared file. I considered these approaches: 1. Store the attachment in Notes Document 2. Store the attachment in database profile

but in both cases I will need to add extra UI design elements (form, view... ) So the easiest way to maintain it - use db Resources (images or files). I need to create LotusSrcit action that would access the file from db Resources and attach it into new NotesDocument that will be sent as an email.

1 and #2 easy to implement. But how can I access certain file resource from db Resources?

1
DB resources require designer access to the database. If you need to change the attachment in the future, just put in a special document.umeli

1 Answers

1
votes

You can access file or image resources using the NotesNoteCollection class. However, since Notes stores the attached files or images in its own, internal format, it is not easy -- if at all possible -- to access those attachments using pure LotusScript.

A workaround that I found useful is to attach the file to an Applet resource, where it can be accessed using pure LotusScript; see sample code below.

Dim sn As New NotesSession()
Dim db as NotesDatabase
Dim nc As NotesNoteCollection
Dim designNote As NotesDocument
Dim eo As NotesEmbeddedObject
Dim noteID$, myFileName$

myFileName = "foobar.txt"

Set db = sn.CurrentDatabase
Set nc = db.CreateNoteCollection(False)
nc.SelectJavaResources = True 'select all Applet resources
nc.SelectionFormula = {$TITLE="} + myFileName + {"} 'assuming the Applet resource has the same name as the file
Call nc.BuildCollection()
noteID = nc.GetFirstNoteID()
Do Until Len(noteID) = 0
    Set designNote = db.GetDocumentByID(noteID)
    Set eo = designNote.GetAttachment(myFileName)
    If Not (eo Is Nothing) Then
        '----- your code goes here -----
        Exit Do
    End If
    noteID = nc.GetNextNoteID(noteID)
Loop

I'm making two assumptions here:

  1. The name of the file you want to access is known ("foobar.txt" in the sample code). This is necessary, since otherwise you won't be able to access the attachment.
  2. The Applet resource has the same name as the attached file. Not necessary, but convenient for being able to filter the NotesNoteCollection by the very name of the attached file.