如何通过LotusScript访问文件资源

时间:2019-09-07 22:04:02

标签: lotus-notes lotus-domino

我要访问和使用共享文件。我考虑了以下方法: 1.将附件存储在Notes文档中 2.将附件存储在数据库配置文件中

但在两种情况下,我都需要添加额外的UI设计元素(窗体,视图...) 因此,最简单的维护方法-使用db资源(图像或文件)。 我需要创建LotusSrcit操作,该操作将从db Resources中访问文件并将其附加到新的NotesDocument中,该文件将作为电子邮件发送。

1和#2易于实现。但是如何从db资源访问某些文件资源?

1 个答案:

答案 0 :(得分:0)

您可以使用NotesNoteCollection类访问文件或图像资源。但是,由于Notes以其自己的内部格式存储附件或图像,因此,即使有可能,也不容易使用纯LotusScript访问这些附件。

我发现一个有用的解决方法是将文件附加到Applet资源,可以使用纯LotusScript访问该文件;参见下面的示例代码。

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

我在这里做两个假设:

  1. 您要访问的文件的名称是已知的(示例代码中为“ foobar.txt”)。这是必要的,因为否则您将无法访问附件。
  2. Applet资源的名称与附件相同。不必要,但很方便,因为它可以通过附件的名称来过滤NotesNoteCollection。