Greetings,
I am trying to print Notes Docs to PDF in VB.Net using NotesUI objects. Following is the code I am using.
ws = CreateObject(“Notes.NotesUIWorkspace”)
Call ws.OpenDatabase(“”, nsfFile)
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)
args1(0) = CType(notesDoc.UniversalID, System.Object)
DocObj = notesUIWorkspaceType.InvokeMember(“GetDocumentByUNID”, Reflection.BindingFlags.InvokeMethod, Nothing, DBObj, args1)
args2(0) = CType(False, System.Object) 'read mode
args2(1) = CType(DocObj, System.Object) 'doc to open
args2(2) = CType(True, System.Object) 'lock only read-mode
args2(3) = CType(“”, System.Object) 'anchor
args2(4) = CType(True, System.Object) 'return the notesUIDoc
args2(5) = CType(False, System.Object) 'do not create a new instance
'-----------Exception here----
resObj = notesUIWorkspaceType.InvokeMember(“EditDocument”, Reflection.BindingFlags.InvokeMethod, Nothing, WSObj, args2)
Thread.Sleep(100)
nc = 1
args3(0) = CType(nc, System.Object)
notesUIWorkspaceType.InvokeMember(“PRINT”, Reflection.BindingFlags.InvokeMethod, Nothing, resObj, args3)
args4(0) = CType(Nothing, System.Object)
notesUIWorkspaceType.InvokeMember(“CLOSE”, Reflection.BindingFlags.InvokeMethod, Nothing, resObj, args4)
Thread.Sleep(500)
resObj = Nothing
GC.Collect()
It works fine for a few NSFs but on other NSFs it crashes. The exception that I get is
“System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> System.Runtime.InteropServices.COMException (0x80010105): The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))”
On one of the NSFs which had about 3000 documents, the code sometimes failed at a particular doc, but other times it processed the doc fine. The form associated with the doc is “Notice”
I tried disabling the Agents in the database and then printing, but the code crashed at another document. When I looked at the log.nsf file it showed the following message:
“Client Execution Security is enabled.”
Is there some way to disable the security that might help print all the docs successfully?? or
Is there something wrong in my approach?? or
Does the User / Security preferrence of the Notes Client need to be changed??
Any help on this will be greatly appreciated!! Thanks!!