LotusWorst
LotusWorst

Reputation: 31

Lotus Notes : Not able to access properties file in lotuscript

Hi friends i want to access the properties file from machine from the specified path. For java Agent i used Properties method and extracted the data from the properties file. but now i want it to be done in lotuscript. I tried using properties method but it didnt work so i thought to read properties with the below code.

'Dim ColFileName As String
    'ColFileName="C:\abcd.properties"
    Open ColFileName For Input As 1
    Do While Not EOF(1)
    Line Input #1,txt$
    MsgBox "TEXT FILE:"+txt$ 

In properties file i have a written it as col=start

where i want to get the property of the col using getProperty method in java same way for lotusscript. I added the above code but it is not working. Can anyone tell what mistake i have committed.

Upvotes: 0

Views: 363

Answers (1)

JSmart523
JSmart523

Reputation: 2497

In Options

%Include "lserr.lss" 'This is just a list of constants.

Add these functions somewhere:

%REM
    Function fstreamOpenFile(sPath As String, bTruncate As Boolean, bConfirmExists As Boolean) As NotesStream
    <dl>
    <dt>sPath</dt><dd>Filepath of the file to be opened/created.</dd>
    <dt>bTruncate</dt><dd>Boolean. True if file is for output and any existing file should be replaced rather than appended to.</dd>
    <dt>bConfirmExists</dt><dd>Boolean. If True, and the opened file is empty, then an ErrFileNotFound error will be thrown.</dd>
    </dl>
%END REM
Function fstreamOpenFile(sPath As String, bTruncate As Boolean, bConfirmExists As Boolean) As NotesStream
    Dim session as New NotesSession     Dim stream As NotesStream

    Set stream = session.Createstream()
    If Not stream.Open(sPath) Then Error ErrOpenFailed, {Could not open file at "} + sPath + {"}
    If bConfirmExists And stream.Bytes = 0 Then Error ErrFileNotFound, {File at "} + sPath + {" is missing or empty.} 
    If bTruncate Then Call stream.Truncate()
    Set fstreamOpenFile = stream
End Function

Function fsPropertyFileValue(sFilePath As String, sPropertyName As String, sDefaultValue As String) As String
    On Error GoTo ErrorQuietly
    Dim stream As NotesStream
    Dim sLine As String
    Dim sLeft As String
    Dim iLeftLen As Integer

    Set stream = fstreamOpenFile(sFilePath, False, True)
    sLeft = sPropertyName + "="
    iLeftLen = Len(sLeft)
    Do
        sLine = stream.Readtext
        If Left(sLine, iLeftLen) = sLeft Then
            fsPropertyFileValue = Right(sLine, Len(sLine) - iLeftLen)
            Exit Function
        End If
    Loop Until stream.Iseos
ReturnDefault:
    fsPropertyFileValue = sDefaultValue
    Exit Function
ErrorQuietly:
    Print Now, Error$
    Resume ReturnDefault
End Function

(Notes: I have not tested/debugged fsPropertyFileValue. The html tags in the comment is because, when editing an agent or script library, the designer client will parse and display the HTML tags.)

Then you can use fsPropertyFileValue("C:\abcd.properties", "col", "start") to get the value of the col property within C:\abcd.properties and, if that fails, use "start".

Upvotes: 1

Related Questions