Friday, September 21, 2007

Invoking Lotus Notes Session in VB.NET

For the record, this is how to invoke Lotus Notes Session in VB.NET:

 

Procedure 1:

    Private Sub InitLotusNotesSession()

        bStatus = SetLoginUser(INIFilePath & "Spec.id", sCurrUserID)

        If (bStatus = True) Then

            bStatus = InitGUINotesSession()

            If (bStatus = True) Then

                bStatus = SetLoginUser(sCurrUserID, sNewUserID)

            Else

                Exit Sub

            End If

        Else

            Exit Sub

        End If

    End Sub

 

Procedure 2:

    Private Function SetLoginUser(ByVal myNewUserID As String, ByVal myCurrentUserID As String) As Boolean

        Dim sNotesIniFile As String

        Dim objINI As New _IniFile

        Dim INIFile As String = "Intfc.ini"

        With objINI

            .Path = INIFilePath & INIFile

            .Section = "LOTUS_NOTES"

            .myDefault = "NOT AVAILABLE"

            .Key = "INI_FILE"

            sNotesIniFile = .myValue

            Debug.WriteLine(.Success)

        End With

        If (sNotesIniFile <> "NOT AVAILABLE") Then

            With objINI

                .Path = sNotesIniFile

                .Section = "Notes"

                .myDefault = "NOT AVAILABLE"

                .Key = "KeyFilename"

                myCurrentUserID = .myValue

                If (sCurrUserID <> "NOT AVAILABLE") Then

                    .myValue = myNewUserID

                Else

                    SetLoginUser = False

                    Exit Function

                End If

            End With

        Else

            SetLoginUser = False

            Exit Function

        End If

        SetLoginUser = True

        sNewUserID = myNewUserID

        sCurrUserID = myCurrentUserID

    End Function

 

Procedure 3:

    Private Function InitGUINotesSession() As Boolean

        Try

            InitGUINotesSession = False

            gobjSession = CreateObject("Lotus.NotesSession")

            Call gobjSession.Initialize(myPassword)

            gobjDB = gobjSession.GetDatabase(myServer, mydBase)

            InitGUINotesSession = True

            Exit Function

        Catch ex As Exception

            'MsgBox(ex.ToString & vbCrLf & vbCrLf & " Error in Initializing Notes Session!")

            Logger.LogWithDate(LogFile, ex.ToString & vbCrLf & vbCrLf & " Error in Initializing Notes Session!")

            InitGUINotesSession = False

        End Try

    End Function

 

Brief Description:

1. SetLoginUser is the procedure that captures the current LN user, and replaces it with the user ID (Spec.ID), the account that the program uses. It is reading the data set from the .ini file.

2. gobjSession is a Domino.NotesSession-type variable/object.

3. gobjDB is a Domino.NotesDatabase-type variable/object.

 

No comments: