Greetings,
I am trying to print all the documents in a particular View in a given NSF. I am doing this in VB.Net by using late binding calls. Following is my code.
'variable declarations
Dim notesSession As Domino.NotesSession
Dim notesDBDir As Domino.NotesDbDirectory
Dim notesDatabase As Domino.NotesDatabase
Dim notesView As Domino.NotesView
Dim notesDoc As Domino.NotesDocument
Dim ws As Object
Dim WSObj As Object
Dim UIDBObj As Object
Dim DBObj As Object
Dim DocObj As Object
Dim notesUIWorkspaceType As Type
Dim args1(0) As Object
Dim args2(5) As Object
Dim args3(0) As Object
Dim args4(0) As Object
Dim nc As Int16
Dim resObj As Object
public subPrintAllDocs_Inbox()
'Front End Classes
ws = CreateObject(“Notes.NotesUIWorkspace”)
Call ws.OpenDatabase(“”, “test.nsf”)
notesUIWorkspaceType = Type.GetTypeFromProgID(“Notes.NotesUIWorkspace”)
WSObj = Activator.CreateInstance(notesUIWorkspaceType)
UIDBObj = notesUIWorkspaceType.InvokeMember("CurrentDatabase", Reflection.BindingFlags.GetProperty, Nothing, WSObj, Nothing)
DBObj = notesUIWorkspaceType.InvokeMember(“Database”, Reflection.BindingFlags.GetProperty, Nothing, UIDBObj, Nothing)
'Back End Classes
'Open a Session and initialize it
notesSession = New Domino.NotesSession()
notesSession.Initialize()
'Get the database Directory
notesDBDir = notesSession.GetDbDirectory(“”)
'Get the Database
notesDatabase = notesDBDir.OpenDatabase(“test.nsf”)
If Not (notesDatabase.IsOpen) Then
notesDatabase.Open()
End If
'Get the ($Inbox) View
notesView = notesDatabase.GetView(“($Inbox)”)
'Start Printing Documents
notesDoc = notesView.GetFirstDocument()
While Not (notesDoc Is Nothing)
args1(0) = CType(notesDoc.UniversalID, System.Object)
DocObj = notesUIWorkspaceType.InvokeMember(“GetDocumentByUNID”, Reflection.BindingFlags.InvokeMethod, Nothing, DBObj, args1)
args2(0) = CType(False, System.Object)
args2(1) = CType(DocObj, System.Object)
args2(2) = CType(True, System.Object)
args2(3) = CType(“”, System.Object)
args2(4) = CType(True, System.Object)
args2(5) = CType(False, System.Object)
resObj = notesUIWorkspaceType.InvokeMember(“EditDocument”, Reflection.BindingFlags.InvokeMethod, Nothing, WSObj, args2)
nc = 1
args3(0) = CType(nc, System.Object)
notesUIWorkspaceType.InvokeMember(“PRINT”, Reflection.BindingFlags.InvokeMethod, Nothing, resObj, args3)
args4(0) = CType(False, System.Object)
notesUIWorkspaceType.InvokeMember(“CLOSE”, Reflection.BindingFlags.InvokeMethod, Nothing, resObj, args4)
notesDoc = notesView.GetNextDocument(notesDoc)
End While
End Sub
This code works fine for small NSF files, but if the NSF file contains more than 500 documents, the program crashes. I am not sure if this is a late binding issue with .Net or if its something in my code.
Please do advice if there is a better way to print the docs to pdf or the code above can be tweaked.
Any help will be greatly appreciated.
Thanks in advance.