例: Working with attachments and embedded objects in LotusScript® classes

  1. 次のエージェントは、添付ファイルを取得する NotesRichTextNavigator メソッドを使用して、現在の文書の Body アイテムの添付ファイルを抽出します。
    REM Run this against a selected document that has Body field
    REM Body field should contain file attachments
    Sub Initialize
      Dim session As NotesSession
      Dim db As NotesDatabase
      Dim dc As NotesDocumentCollection
      Dim doc As NotesDocument
      Dim body As NotesRichTextItem
      Dim rtnav As NotesRichTextNavigator
      Dim att As NotesEmbeddedObject
      Set session = New NotesSession
      Set db = session.CurrentDatabase
      Set dc = db.UnprocessedDocuments
      Set doc = dc.GetFirstDocument
      If Not doc.HasEmbedded Then Exit Sub
      Set body = doc.GetFirstItem("Body")
      Set rtnav = body.CreateNavigator
      
      REM Get attachments
      If rtnav.FindFirstElement(RTELEM_TYPE_FILEATTACHMENT) Then
        Do
          Set att = rtnav.GetElement()
          filepath$ = "C:¥Files¥" & att.Source
          Call att.ExtractFile(filepath$)
          Print filepath$ & " extracted"
        Loop While rtnav.FindNextElement()
      End If
    End Sub
  2. 次のエージェントは、添付ファイルを取得する NotesRichTextItem.EmbeddedObjects プロパティを使用して、現在の文書の Body アイテムの添付ファイルを抽出します。
    REM Run this against a selected document that has Body field
    REM Body field should contain file attachments
    Sub Initialize
      Dim session As NotesSession
      Dim db As NotesDatabase
      Dim dc As NotesDocumentCollection
      Dim doc As NotesDocument
      Dim body As NotesRichTextItem
      Set session = New NotesSession
      Set db = session.CurrentDatabase
      Set dc = db.UnprocessedDocuments
      Set doc = dc.GetFirstDocument
      If Not doc.HasEmbedded Then Exit Sub
      Set body = doc.GetFirstItem("Body")
      
      REM Get attachments
      Forall att In body.EmbeddedObjects
        If att.Type = EMBED_ATTACHMENT Then
          filepath$ = "C:¥Files¥" & att.Source
          Call att.ExtractFile(filepath$)
          Print filepath$ & " extracted"
        End If
      End Forall
    End Sub
  3. 次のフォームのアクションの例では、文書のすべての埋め込みオブジェクトのプロパティを表示します。
    Sub Click(Source As Button)
      Dim workspace As New NotesUIWorkspace
      Dim uidoc As NotesUIDocument
      Dim doc As NotesDocument
      Dim item As Variant
      Set uidoc = workspace.CurrentDocument
      Set doc = uidoc.Document
      Set item = doc.GetFirstItem("Body")
      Forall embobj In item.EmbeddedObjects
        verbs = "No verbs"
        Select Case embobj.Type
        Case EMBED_OBJECTLINK : _
        embobjType = "Object link"
        Case EMBED_ATTACHMENT : _
        embobjType = "Attachment"
        Case EMBED_OBJECT : embobjType = "Object"
          verbs = "Verbs:"
          Forall verb In embobj.Verbs
            verbs = verbs & " " & verb
          End Forall
        End Select
        Messagebox "Name: " & embobj.Name & Chr(10) _
        & "Class: " & embobj.Class & Chr(10) _
        & "File size: " & embobj.FileSize & Chr(10) _
        & "Type: " & embobjType & Chr(10) & verbs
      End Forall
    End Sub
  4. 次のフォームのアクションの例では、文書に最初に埋め込まれたオブジェクトまたは唯一埋め込まれているオブジェクトを起動します。
    Sub Click(Source As Button)
      Dim workspace As New NotesUIWorkspace
      Dim uidoc As NotesUIDocument
      Dim doc As NotesDocument
      Dim item As Variant
      Set uidoc = workspace.CurrentDocument
      Set doc = uidoc.Document
      Set item = doc.GetFirstItem("Body")
      If Isempty (item.EmbeddedObjects) Then
        Messagebox "No embedded object in document"
        Exit Sub
      End If
      If item.EmbeddedObjects(0).Type <> EMBED_OBJECT Then
        Messagebox "Object not an embedded object"
        Exit Sub
      End If
      Call item.EmbeddedObjects(0).Activate(True)
    End Sub