0

I want to access a Lotus Notes Database and get attachments from documents in it. I can open the DB and doc and loop through all items. The problem is, I can not use the items as NotesRichTextItem and therefore not check if there are any item.EmbeddedObject. I guess it is a problem with declaration of the items. In general: If I debug using VS2010, doc and the database and NotesSession have the "value" System.__ComObject and "type" is the Domino.Notes Object it should be. e.g. doc in WATCH:

Name   VALUE                 TYPE     
doc    {System.__ComObject}  Domino.NotesDocument

but if I use the doc.GetType() command the result is

doc.GetType()  = {Name = "__ComObject" FullName = "System.__ComObject"} 

Since I do not know if my doc.item is a NotesRichTextItem, I define it as an object and want to check afterwards is type. Which I can't since the return value of the functions is as above for doc, too. Here is the complete code I use currently, I loaded the Lotus Domino reference from the COM section.

Public Sub OpenDocumentLN()
        Try
      Dim ns As New Domino.NotesSession
      Dim db As Domino.NotesDatabase
      Dim doc As Domino.NotesDocument
      Dim view As Domino.NotesView

      If Not (ns Is Nothing) Then
        ns.Initialize()
        db = ns.GetDatabase("", sLotusNotesPath & sLotusNotesDB, False)
        If Not (db Is Nothing) Then
          view = db.GetView(sLotusView)
          doc = view.GetFirstDocument
          While Not doc Is Nothing
            Dim lnNextDoc As Domino.NotesDocument = view.GetNextDocument(doc)

            For Each item As Domino.NotesItem In doc.Items
              Dim rtItem As Object = doc.GetFirstItem(item.Name)

              If rtItem Is Nothing Then Continue For
             If Not rtItem.GetType() = GetType(Domino.NotesRichTextItem) Then Continue For
             ' NEVER reach this part of the code since the IF clause prevents it due to the type problem
              If rtItem.EmbeddedObjects Is Nothing Then Continue For
              For Each o As Domino.NotesEmbeddedObject In rtItem.EmbeddedObjects
                o.ExtractFile(sLotusExportPath & o.Source)
              Next

            Next
            doc = lnNextDoc
          End While

        End If
        db = Nothing
        ns = Nothing
      End If
    Catch ex As Exception

    End Try
  End Sub

How can I use my rtitem as a NotesRichTextItem so I can handle it appropiate? And why are all objects are treated als ComObjects?

user49017
  • 25
  • 9
  • 1
    https://msdn.microsoft.com/en-us/library/zyy863x8.aspx – Hans Passant Aug 01 '16 at 14:25
  • Thank you, using TryCast seems to work. I also found that 'If Not Microsoft.VisualBasic.Information.TypeName(rtItem) = "IRichTextItem" ' does the trick, but it seems less sound. – user49017 Aug 01 '16 at 14:52

0 Answers0