Wednesday, December 1, 2010

Lotusscript code to import dxl to current database

Function importDxl(dxlFilePath) As Boolean

'***********************************************************
'@Purpose : To import dxl into current database 
'@Author   : Karthikeyan A
 '@Note : The dxl file should contain the dxl that corresponds to a notes document in this case
'*********************************************************** 

'mark the flow of control moving into  the current function
importDxl=False

'declare all variables and objects necessary for further manipulation
Dim session As New NotesSession
Dim dbdir As NotesDbDirectory
Dim db As NotesDatabase
Dim stream As NotesStream
Dim importer As NotesDXLImporter

'handle errors in case of abrupt termination
On Error Goto errHandler

REM set handle for the current database
Set db = session.CurrentDatabase

'create a stream
Set stream = session.CreateStream

'open the dxl file to be imported
If Not stream.Open(dxlFilePath) Then
Msgbox "Cannot open " & dxlFilePath, , "Error"
Exit Function
End If
'if the file is empty then inform the same to the user and exit
If stream.Bytes = 0 Then
Msgbox "File did not exist or was empty", , dxlFilePath
Exit Function
End If

REM Import DXL into current database
Set importer = session.CreateDXLImporter
importer.ReplaceDBProperties = False
importer.ReplicaRequiredForReplaceOrUpdate = False
importer.ACLImportOption = DXLIMPORTOPTION_REPLACE_ELSE_IGNORE
importer.DesignImportOption = DXLIMPORTOPTION_REPLACE_ELSE_IGNORE
Call importer.Import(stream, db)

'close the current stream
Call stream.Close

'mark the flow of control moving out of  the current function
importDxl=True
Exit Function
'display the errors that resulted in abrupt termination
errHandler:
Print "Error ***" & Error & " occured on line ***" & Cstr(Erl) & "*** with error number ***" & Cstr(Err)  & "*** while attempting to importDxl"
Msgbox "Error ***" & Error & " occured on line ***" & Cstr(Erl) & "*** with error number ***" & Cstr(Err)  & "*** while attempting to importDxl"
Exit Function
End Function

Hope this helps:)

No comments:

Post a Comment