如何通过 LotusScript 访问文件资源
How to access file resource via LotusScript
我想访问和使用共享文件。我考虑了这些方法:
1.将附件保存在Notes Document中
2. 将附件存储在数据库配置文件中
但在这两种情况下,我都需要添加额外的 UI 设计元素(表单、视图...)
所以维护它的最简单方法——使用 db 资源(图像或文件)。
我需要创建 LotusSrcit 操作,该操作将从数据库资源访问文件并将其附加到将作为电子邮件发送的新 NotesDocument 中。
1 和#2 易于实施。但是如何从数据库资源访问某些文件资源?
您可以使用 NotesNoteCollection class 访问文件或图像资源。但是,由于 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
我在这里做两个假设:
- 您要访问的文件的名称已知(示例代码中的"foobar.txt")。这是必要的,否则您将无法访问附件。
- 小程序资源与附件同名。不是必需的,但可以方便地按附件名称过滤 NotesNoteCollection。
我想访问和使用共享文件。我考虑了这些方法: 1.将附件保存在Notes Document中 2. 将附件存储在数据库配置文件中
但在这两种情况下,我都需要添加额外的 UI 设计元素(表单、视图...) 所以维护它的最简单方法——使用 db 资源(图像或文件)。 我需要创建 LotusSrcit 操作,该操作将从数据库资源访问文件并将其附加到将作为电子邮件发送的新 NotesDocument 中。
1 和#2 易于实施。但是如何从数据库资源访问某些文件资源?
您可以使用 NotesNoteCollection class 访问文件或图像资源。但是,由于 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
我在这里做两个假设:
- 您要访问的文件的名称已知(示例代码中的"foobar.txt")。这是必要的,否则您将无法访问附件。
- 小程序资源与附件同名。不是必需的,但可以方便地按附件名称过滤 NotesNoteCollection。