0
votes

I use the following code to pull the contents of a .log (text) file into a Notes rich text field, but it fails if the amount of data is > 64 KB:

Dim io As Integer
Dim text As String
Dim fileSize As Single

io = Freefile
fileSize = 0

Open f For Input As io
fileSize = Filelen( f )

If (fileSize > 65536) Then
    Msgbox "Sorry, but the file " + f + " is > 64KB and cannot be rendered in the default rich text field.",, "Can't continue"
    Close #io
    Exit Sub
End If

While Not(Eof(io))
    Line Input #io, text
    Call uid.FieldAppendText("RT1", text + Chr(13) + Chr(10))
Wend

Close #io

I check the file size to avoid the error (which is a complaint that a paragraph can't exceed 64KB). So how do you add multiple paragraphs, so you can display more than 64KB of data?

2

2 Answers

2
votes

You insert a line break to create paragraphs larger than 64KB. But you should be using back-end classes when you manipulate Rich Text fields.

2
votes

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,

  1. set a NotesStream variable to fstreamOpenFile(sFilePath, False, True)
  2. get/create a NotesRichTextItem object
  3. pass the NotesStream and NotesRichTextItem objects to subImportStreamToRT
  4. save your NotesDocument
  5. give it a try and debug the code because, again, subImportStreamToRT isn't tested.