LOTUSSCRIPT/COM/OLE CLASSES


Examples: Truncate method
This agent opens a stream for a file and writes to it. If the file already has content, the agent asks the user whether to abort. If the user chooses to proceed, the agent asks the user whether to rewrite the file or append to it. If the user chooses to rewrite, the agent truncates the stream before writing to it.

%INCLUDE "lsconst.lss"
Sub Initialize
 Dim session As NotesSession
 Dim db As NotesDatabase
 Dim dc As NotesDocumentCollection
 Dim doc As NotesDocument
 Dim stream As NotesStream
 Dim pathname As String
 pathname = "c:\StreamFiles\"
 Set session = New NotesSession
 Set db = session.CurrentDatabase
 Set dc = db.UnprocessedDocuments
 Set doc = dc.GetFirstDocument
 Set stream = session.CreateStream
 pathname = pathname & doc.GetItemValue("Subject")(0) & ".txt"
 If Not stream.Open(pathname, "ASCII") Then
   Messagebox pathname,, "Open failed"
   Exit Sub
 End If
 If stream.IsReadOnly Then
   Messagebox pathname,, "File is read-only"
   Exit Sub
 End If
 If stream.Bytes <> 0 Then
   If Messagebox("Do you want to abort?", _
   MB_YESNO + MB_ICONQUESTION, _
   "File exists and has content?") = IDYES Then
     Exit Sub
   End If
   If Messagebox("Do you want to replace the old content?", _
   MB_YESNO + MB_ICONQUESTION, _
   "Rewrite or append?") = IDYES Then
     Call stream.Truncate
   Else
     Call stream.WriteText(Chr(13) & Chr(10))
   End If
 End If
 Call stream.WriteText(doc.GetItemValue("Body")(0))
 Call stream.Close
End Sub

See Also