Printing Docs to PDF - Notes Client crashes

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!!

Subject: Printing Docs to PDF - Notes Client crashes

I have no idea why your code sometimes fails, but could it be that in some cases your sleep is not long enough? I am always alert when I see these type of commands in the coding.

Subject: RE: Printing Docs to PDF - Notes Client crashes

Thanks for the response.

I did increase both the sleeps and that did not do the trick.

I does work fine with regular emails (“Memo” and “Reply” forms) but it seems to have some issues with “Appointment” and “Notice” forms. Guess its the calendar items.

An acceptable workaround would be, if one document does not print for some reason, I can skip it and move on the next one. The issue I am running into with this is that, if the document fails to print, it crashes the NotesUI objects and I am not able to print (rather “Edit”) later documents.

The document that failed gives me the following exception:

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))

— End of inner exception stack trace —

and the later documents give me the following exception

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> System.Runtime.InteropServices.COMException (0x00001142): Property or Method is not available during QueryOpen: EditDocument

If there is some way I can move on the next document if one document fails, that will be of great help too.

Thanks in advance.

Subject: RE: Printing Docs to PDF - Notes Client crashes

There is a command “on error resume next”, but be careful that when you continue you are sure that the logic still works. So check any variable for content, because its assignment might have failed.

Alternatively you could have some code like:

on error goto label1

call print-func (here things could go wrong)

label1:

Be sure not to have any on error’s active in your function or any subfunction.

Subject: RE: Printing Docs to PDF - Notes Client crashes

Thanks for the response.

I am using Try…Catch blocks in VB.Net to trap and handle exceptions.

The layout of my code is

Try

print-func( )

Catch ex as Excpetion

log this doc as an exception doc

The issue is not in catching the exception, the issue is in moving to the next doc.

When I encounter a exception Doc, then the Notes Workspace “hangs” and I am not able to reopen or reload the workspace. When I do try n recreate the workspace objects as follows:

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)

the workspaces is all Gray and I am not able to access later documents.

Any ideas, how I can maybe reload the workspace or close and open it up again??

Thanks in advance.