Skip to main content

Examples: SetInput method

  1. This agent generates DXL based on the content of a database.
Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Set db = session.CurrentDatabase

REM Open xml file named after current database
Dim stream As NotesStream
Set stream = session.CreateStream
filename$ = "c:\dxl\" & _
Left(db.FileName, Len(db.FileName) - 3) & "xml"
If Not stream.Open(filename$) Then
Messagebox "Cannot open " & filename$,, "Error"
Exit Sub
End If
Call stream.Truncate

REM Export current database as DXL
Dim exporter As NotesDXLExporter
Set exporter = session.CreateDXLExporter
Call exporter.SetInput(db)
Call exporter.SetOutput(stream)
Call exporter.Process
End Sub
  1. This agent generates DXL based on the content of a document collection.
Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Set db = session.CurrentDatabase

REM Open xml file named after current database
Dim stream As NotesStream
Set stream = session.CreateStream
filename$ = "c:\dxl\" & _
Left(db.FileName, Len(db.FileName) - 4) & "_dc.xml"
If Not stream.Open(filename$) Then
Messagebox "Cannot open " & filename$,, "Error"
Exit Sub
End If
Call stream.Truncate

REM Create document collection
Dim dc As NotesDocumentCollection
Set dc = db.AllDocuments
If dc.Count = 0 Then
Messagebox "No document in database",, "No document"
Exit Sub
End If

REM Export document collection as DXL
Dim exporter As NotesDXLExporter
Set exporter = session.CreateDXLExporter
Call exporter.SetInput(dc)
Call exporter.SetOutput(stream)
Call exporter.Process
End Sub
  1. This agent generates DXL based on the content of a document.
Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Set db = session.CurrentDatabase

REM Open xml file named after current database
Dim stream As NotesStream
Set stream = session.CreateStream
filename$ = "c:\dxl\" & _
Left(db.FileName, Len(db.FileName) - 4) & "_doc.xml"
If Not stream.Open(filename$) Then
Messagebox "Cannot open " & filename$,, "Error"
Exit Sub
End If
Call stream.Truncate

REM Get selected or first selected document
Dim dc As NotesDocumentCollection
Set dc = db.UnprocessedDocuments
If dc.Count = 0 Then
Messagebox "No document selected",, "No document"
Exit Sub
End If
Dim doc As NotesDocument
Set doc = dc.GetFirstDocument

REM Export document as DXL
Dim exporter As NotesDXLExporter
Set exporter = session.CreateDXLExporter
Call exporter.SetInput(doc)
Call exporter.SetOutput(stream)
Call exporter.Process
End Sub
  1. This code is on a form. Two fields provide the pathname of an input file and the name of an output database. A "Process" button sets the input and output parameters for a NotesDXLImporter object and calls its Process method.
Dim session As NotesSession
Dim ws As NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim importer As NotesDXLImporter
Dim stream As NotesStream
Dim db As NotesDatabase

Sub Initialize
Set session = New NotesSession
Set ws = New NotesUIWorkspace
Set importer = session.CreateDXLImporter
End Sub

Function SetInput As Boolean
Set stream = session.CreateStream
fileName$ = uidoc.FieldGetText("InputFile")
If Not stream.Open(fileName$) Then
Messagebox "Cannot open file",, fileName$
SetInput = False
Exit Function
End If
If stream.Bytes = 0 Then
Messagebox "File did not exist or was empty",, fileName$
SetInput = False
Exit Function
End If
Call importer.SetInput(stream)
SetInput = True
End Function

Function SetOutput As Boolean
Set db = New NotesDatabase("", "")
fileName$ = uidoc.FieldGetText("OutputDatabase")
If Not db.Open("", fileName$) Then
Call db.Create("", fileName$, True)
End If
Call importer.SetOutput(db)
SetOutput = True
End Function

Sub Postopen(Source As Notesuidocument)
Set uidoc = ws.CurrentDocument
End Sub

Sub Click(Source As Button)
REM This is the "Process" button
If Not SetInput Then Exit Sub
If Not SetOutput Then Exit Sub
Call importer.Process
End Sub