Use NotesStream to read one line at a time, and then use NotesRichTextItem's AppendText and AddNewLine(1, True)
The subImportStreamToRT subroutine below is untested, so Murphy's Law says there's a big in here somewhere, but at least it compiles! Good luck!
Option Public
Option Declare
%Include "lserr.lss"
%REM
Function fstreamOpenFile(sPath As String, bTruncate As Boolean, bConfirmExists As Boolean) As NotesStream
<br>
<b>Arguments</b>
<blockquote><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></blockquote>
%END REM
Public Function fstreamOpenFile(sPath As String, bTruncate As Boolean, bConfirmExists As Boolean) As NotesStream
Dim bFlag As Boolean
Dim session As New NotesSession
Dim stream As NotesStream
If sPath = "" Then Error 13, "No path supplied."
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
%REM
Sub subImportStreamToRT(stream As NotesStream, rt As NotesRichTextItem)
For each line of text in the stream, appends that text in its own paragraph.
Assumes that the first line of text can simply be appended without first creating a new paragraph. (e.g. rt is a blank field or you've already added a new line before calling this function)
<br>
<b>Arguments</b>
<blockquote><dl><dt>stream As NotesStream</dt><dd>NotesStream containing text to be imported into a rich text file</dd>
<dt>rt As NotesRichTextItem</dt><dd>NotesRichTextItem to import stream's text into.</dd></dl></blockquote>
%END REM
Sub subImportStreamToRT(stream As NotesStream, rt As NotesRichTextItem)
If Not stream.IsEOS Then
Do
rt.AppendText stream.ReadText(STMREAD_LINE, EOL_ANY)
If stream.IsEOS Then
Exit Sub
Else
rt.AddNewLine 1, True
End If
Loop
End If
End Sub
To use,
- set a NotesStream variable to
fstreamOpenFile(sFilePath, False, True)
- get/create a NotesRichTextItem object
- pass the NotesStream and NotesRichTextItem objects to subImportStreamToRT
- save your NotesDocument
- give it a try and debug the code because, again, subImportStreamToRT isn't tested.