lotus-notes - 如何通过 LotusScript 访问文件资源
问题描述
我想访问和使用共享文件。我考虑了这些方法: 1. 将附件存储在 Notes 文档中 2. 将附件存储在数据库配置文件中
但在这两种情况下,我都需要添加额外的 UI 设计元素(表单、视图......)所以维护它的最简单方法 - 使用 db 资源(图像或文件)。我需要创建 LotusSrcit 操作,该操作将从 db Resources 访问文件并将其附加到将作为电子邮件发送的新 NotesDocument 中。
1和#2易于实现。但是如何从 db Resources 访问某些文件资源?
解决方案
您可以使用 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
我在这里做了两个假设:
- 您要访问的文件的名称是已知的(示例代码中的“foobar.txt”)。这是必要的,否则您将无法访问附件。
- Applet 资源与附件同名。不是必需的,但便于通过附件的名称过滤 NotesNoteCollection。
推荐阅读
- ftp - 仅使用 wget 下载文本文件
- gradle - Gradle:在任务被链接时也运行前置和后置任务?
- python - 自定义包已安装但在另一个项目中找不到
- shell - 将数组的数据插入数据库
- react-native - Expo 是否能够在不需要 Mac 的情况下构建可用于生产的 iOS 应用程序?
- php - 如何以正确的格式序列化实体时间戳以将其与数据表一起使用?
- javascript - 对象不是在 react-sidenav 上使用 withRR4() 的函数
- excel - 特定索引匹配
- mysql - 在 C 中追加或创建文件时如何要求连续块(非碎片)?
- javascript - 在 Javascript 中将对象值打包成一个 4 字节的无符号整数