Notes Stream Question

Hello All

I am using the NotesStream class to create a stream

Dim Stream As NotesStream

I am looping through a collection and appending text to the NotesStream using

Call Stream.WriteText(strHTML)
In strHTMl I am constructing a table using table tags. I do not know if there is a limit on the size of the string because it works for less number of documents but when the number of documents increases there are errors and the tables so constructed do not display properly. I am using
Call mime.SetContentFromText(stream, " {text/html; charset="iso-8859-1"},", ENC_QUOTED_PRINTABLE) to display the tables in RichText fields

Is there any other way I can contruct the table (long string) and add it to the rich text field to display?
Who is Participating?
ee_autoConnect With a Mentor Commented:
Question PAQ'd and stored in the solution database.
If the NotesStream input is the result of NotesStream.WriteText, translation of the internal Unicode defaults to US-ASCII. To translate characters other than US-ASCII, append a charset parameter such as "charset=UTF-8" or "charset=Unicode-1-1" to the type/subtype.

If Content-Type specifies "text" and the "charset" parameter specifies a known Internet encoding, and encoding is ENC_IDENTITY_8BIT or ENC_IDENTITY_BINARY, content storage is with the specified character set. Otherwise, content storage is attempted with US-ASCII.

Also, have you tried other encodings:

Have you set s.ConvertMIME to False before creating MIMEEntity, to avoid converting MIME to rich text?
Sjef BosmanGroupware ConsultantCommented:
Instead of using
   strHTML= strHTML + "blahblah"
use the call more often
   Call Stream.WriteText(strHTML)
and keep the contents of the strHTML variable small. Or even better: don't use it at all.
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

jenvinAuthor Commented:
The size of strHTML is not very long. I make sure that the string is added to the Stream in the loop so that strHTML is not very long. But what i see is that when the number of documents are large the Stream does not seem to be able to contain the long string

I also tried appending two streams

Stream2.Position =0
this did not help

I do not know how to append a stream to a mime entity

Call mime.SetContentFromText(stream, " {text/html; charset="iso-8859-1"},", ENC_QUOTED_PRINTABLE)
How do i append the contents of Stream2 to this mime?
Sjef BosmanGroupware ConsultantCommented:
It's called "set content from text", and not "add content"...

Can you show us the essential lines of the code you're testing?
jenvinAuthor Commented:
Call mime.SetContentFromText(stream, " {text/html; charset="iso-8859-1"},", ENC_QUOTED_PRINTABLE)

Since one Stream is too large i  have divided the stream into two stream. Stream and Stream2. How can i append both the Streams to the same mime item? Is there any other way to store a large string and then save it into a mime item?
Sjef BosmanGroupware ConsultantCommented:
2 Gb ??


I suppose your problem lies elsewhere, not with the NotesStream. Thence my question: can you show us the essential lines of the code you're testing? Meaning ALL the lines, including the loop etc. Otherwise we could be guessing around till kingdom come...
jenvinAuthor Commented:
Here is the code
The agent loops through all the response documents and the html is stored in the stream
There are about 5 tables being updated in the code

The stream size is going beyond the limit is what i think Will it help if I write to a file and keep appending to the string in the file and then finally read from the file?

Is there any such limit on the file read / write operation ?

If not what kind of file do I use?
Sub Initialize
	Dim startTime As Single
	Dim elapsedTime As Single
	startTime! = Timer()
	' This agent loops through all the response documents ie all the response documents and adds all the details of the different tables to the  document
	On Error Goto InitializeError
	Set ses = New NotesSession
	Set ws = New notesuiworkspace
	Set db = ses.CurrentDatabase
	Set uidoc = ws.CurrentDocument
	Set doc= uidoc.Document
	If doc.form(0) = "frmDrrTracker" Then
		Set parentdoc = doc
		parentUnid = doc.UniversalID
		parentUnid = doc.ParentDocumentUNID
		Set parentdoc = db.GetDocumentByUNID(parentUnid)
	End If
	Redim FieldNames(4)
	FieldNames(0) = "rtServiceResp"	
	FieldNames(1) = "rtAddersEUSResp"
	FieldNames(2) = "rtAddersMainlineResp"	
	FieldNames(3) = "rtEngSummaryResp"	
	FieldNames(4) = "rtTATResp"	
	Redim FieldNamesRT(4)
	FieldNamesRT(0) = "rtServiceRespRT"
	FieldNamesRT(1) = "rtAddersEUSRespRT"
	FieldNamesRT(2) = "rtAddersMainlineRespRT"
	FieldNamesRT(3) = "rtEngSummaryRespRT"
	FieldNamesRT(4) = "rtTATRespRT"
	Set stream0 = ses.CreateStream
	Set stream1 = ses.CreateStream
	Set stream2 = ses.CreateStream
	Set stream3 = ses.CreateStream
	Set stream4 = ses.CreateStream
	Set stream5 = ses.CreateStream
	Set stream6 = ses.CreateStream
	Set stream7 = ses.CreateStream
	Set stream8 = ses.CreateStream
	Set stream9 = ses.CreateStream
	ses.ConvertMIME = False 
	Set Collection = parentdoc.Responses	
	Set	Collection = SortDocumentCollection(Collection,"RespSL")
	Dim rtview As NotesView
	Set rtview = db.GetView("AllRichTextResponseDocs")
	Call rtview.Refresh
	Set respDocToUpdate = rtview.getdocumentbykey(parentUnid)
	If respDocToUpdate Is Nothing Then
		Msgbox "Storage document not found. Contact Administrator"
		Exit Sub
	End If
	'the following condition is satisfied when the delete action is performed within the  and there is only one response document that is the rich text
		'clear all rich text fields		and then save the rich text documents or else the changes do not reflect
'	ses.convertmime=False
	Forall fieldn In FieldNamesRT
		'first remove the existing one Then add the newly created value			
		Set mime = respDocToUpdate.GetMIMEEntity(fieldn)
		Dim child As NotesMimeEntity
		If (Not mime Is Nothing) Then			
			Set child = mime.GetFirstChildEntity	
			If Not child Is Nothing Then
				Call child.Remove()
			End If
		End If
		If (Not mime Is Nothing) Then Call mime.Remove()
	'	If doc.CloseMIMEEntities(True, fieldn) Then
		Set item = respDocToUpdate.GetFirstItem(fieldn)
		If Not item Is Nothing Then
			Call respDocToUpdate.RemoveItem(fieldn)
		End If
	'	End If		
	End Forall
	respDocToUpdate.form = "frmRichTextResponse"
	Call respDocToUpdate.ComputeWithForm(False,False)
	Call respDocToUpdate.Save(True,True)
	'If parentdoc.form(0) = "frmDrrTracker" And collection.count = 1 Then
	'	ses.convertmime= True		
	'	Exit Sub
	'End If
	'the ses.ConvertMime mime is again set to false because the rich text storage document is saved and the Convert Mime will be set to true because of that and Mime may not be accessible
	'so set it to false again
	ses.ConvertMIME = False 
	' set the values of all the fields in the streams from all the EUS and the Mainline responses. First set the headers , then the table and finally the footer
	NumOfResp = Collection.Count
	If Not(Collection.Count =0)	Then
		If stream0.Bytes = 0 Then
			Call SetHeaderSol
		End If
		If stream1.Bytes = 0 Then
			Call SetHeaderEUS
		End If
		If stream2.Bytes = 0 Then
			Call SetHeaderMainline
		End If
		If stream3.Bytes = 0 Then
			Call SetHeaderEngStat
		End If
		If stream4.Bytes = 0 Then
			Call SetHeaderTAT
		End If
	End If
	If (NumOfResp Mod 2 = 0) Then
		firstSet = NumOfResp/2
		secondSet = NumOfResp - firstSet
		firstSet = Round(NumOfResp/2, 0)
		secondSet = NumOfResp - firstSet
	End If
	Set responsedoc = Collection.getfirstDocument
	'Set responsedoc = collection.GetNthDocument(k)
	Do While Not ( responseDoc Is Nothing) And Not (responseDoc.Form(0) = "frmRichTextResponse")
		Call AddSolution(FieldNames(0))
		If responseDoc.FormCategory(0) = "EUS"  Then				
			Call AddEUSAdders(FieldNames(1))
			Call AddMainlineAdders(FieldNames(2))
		End If
		Call EngStatusSummary(FieldNames(3))
		Call AddTAT(FieldNames(4))
		Set responseDoc = collection.GetNextDocument(responseDoc)
	'	Set responseDoc = collection.GetNthDocument(k)
	' set the values in the drr document
	'set solution
	Call AddSolFooter
'	Stream0.WriteText("</table>")
	Stream5.Position =0
	'Set mime = respDocToUpdate.CreateMIMEEntity("rtServiceRespRT")
	Set mime = respDocToUpdate.CreateMIMEEntity(FieldNamesRT(0))
	'Dim header As NotesMIMEHeader
	'Set header = mime.CreateHeader("Content-Type")
	'Call header.SetHeaderValAndParams(|multipart;type=Text/HTML:charset="iso-8859-1"|)
	'Dim child As NotesMimeEntity
	'Set child = mime.CreateChildEntity
	'Call mime.SetContentFromText(stream0, {text/html; charset="iso-8859-1"}, ENC_QUOTED_PRINTABLE)
	Call mime.SetContentFromText(stream0, {text/html; charset="iso-8859-1"}, ENC_QUOTED_PRINTABLE)
	'Call child.SetContentFromText(stream5, "", ENC_QUOTED_PRINTABLE)
	Call stream0.truncate
	Call stream5.truncate
	Call stream0.Close
	Call stream5.Close
	'set eus adders
	Call AddEusFooter
	'Stream1.Position = 0
	Stream6.Position = 0
	Set mime = respDocToUpdate.CreateMIMEEntity("rtAddersEUSRespRT")
	Call mime.SetContentFromText(stream1, {text/html; charset="iso-8859-1"}, ENC_QUOTED_PRINTABLE)
	Call stream1.truncate
	Call stream6.truncate
	Call stream1.close
	Call stream6.close
	'set mainline adders
	Call AddMainlineFooter
	Stream7.position =0
	'Stream2.Position = 0
	Set mime = respDocToUpdate.CreateMIMEEntity("rtAddersMainlineRespRT")
	Call mime.SetContentFromText(stream2, {text/html; charset="iso-8859-1"}, ENC_QUOTED_PRINTABLE)
	Call stream2.truncate
	Call stream7.truncate
	Call stream2.close
	Call stream7.close
	'set eng status summary
	Stream8.position =0
	Set mime = respDocToUpdate.CreateMIMEEntity("rtEngSummaryRespRT")
	Call mime.SetContentFromText(stream3, {text/html; charset="iso-8859-1"}, ENC_QUOTED_PRINTABLE)
	Stream3.position =0
	Call stream3.truncate
	Call stream8.truncate
	Call stream3.close
	Call stream8.close
	Stream9.Position = 0
	Set mime = respDocToUpdate.CreateMIMEEntity("rtTATRespRT")
	Call mime.SetContentFromText(stream4, {text/html; charset="iso-8859-1"}, ENC_QUOTED_PRINTABLE)
	Call stream4.truncate
	Call stream9.truncate
	Call stream4.close
	Call stream9.close
	Call respDocToUpdate.Save(True,True)
	ses.ConvertMime = True
	Call Cleanup
	elapsedTime! = Timer() - startTime!
	'Msgbox elapsedTime!
	Exit Sub
	Call cleanup
	ses.ConvertMime = True
	'Error Err
	'Dim ErrorStr As String
	'ErrorStr =  Error & {
'// } & Getthreadinfo(1) & {:} & Erl
	Error Err, Error & {
// } & Getthreadinfo(1) & {:} & Erl
	Exit Sub
End Sub

Open in new window

Sjef BosmanGroupware ConsultantCommented:
Some remarks:
- line 150 isn't correct, it should be split in 2 lines; in LotusScript, unlike C, the whole expression is evaluated, and then the 2nd part will produce an error if doc is Nothing
      Do While Not ( responseDoc Is Nothing)
            If Not (responseDoc.Form(0) = "frmRichTextResponse") Then Exit Do
- you have an On Error; what does it tell you when the code ends, on what line is the error ?
      MsgBox "Error " & Error$ & " on line " & Erl
- I suppose you can combine all strams into one, using
jenvinAuthor Commented:
but the text in each stream is so long that beyond a certain length it just truncates. Is it possible to write the long string to a text file and import into the rich text field as Text / html so as to display the html table? The Rich Text fields are computed fields
Sjef BosmanGroupware ConsultantCommented:
According to the manuals, there is room for 2 Gb in a stream. I can't imagine that you intend to write that much...

> It just truncates
How do you know that? Can you add a test to check that the number of bytes in the stream before and after a WriteText is different?
jenvinAuthor Commented:
I will do that check I will post the results. There are 5 streams if you notice . All of them have different strings . Does all this add up? Also is there a limitation on the text that is put into a rich text field?
Sjef BosmanGroupware ConsultantCommented:
Check here for Notes limits:!OpenDocument

64Kb per paragraph, 64K paragraphs in total, hence 2^32 = 4Gb bytes maximum.
jenvinAuthor Commented:
My long string is one table Does that mean it is one paragraph? Also sorry for asking but how do i check the size of a string in bytes?
jenvinAuthor Commented:
I used the formula (Len(stream0.ReadText) *32)/ 8) and it fails to display the complete table when the number that i got was  504468 bytes

Sjef BosmanGroupware ConsultantCommented:
It is simply stream0.Bytes
jenvinAuthor Commented:
Sowhen the complete table does not display it is 286462 bytes? Please help I am struggling since 2 days!!!!
Sjef BosmanGroupware ConsultantCommented:
I know, so am I :-|

Once it reaches that value, nothing happens? What do you see? Do you get error messages?
Did you try to use the debugger?

You do have to help me in helping you!
jenvinAuthor Commented:
Good news !!!! Looks like I have solved the problem. When i looked into the document properties i saw several $FILE as items
I used the following code to remove the files

If = "$FILE" Then
                  Call i.remove
            End If

after this it seems to show the complete table

I will do some more testing and keep you posted
Sjef BosmanGroupware ConsultantCommented:
$FILE items are attached files, usually attached to a rich-text item. Are you copying complete rich-text items??
jenvinAuthor Commented:
My issue has not been resolved yet. Please help me to create and read MIME_PArt. The content is just text/Html
jenvinAuthor Commented:
Sjef BosmanGroupware ConsultantCommented:
By the way, which Notes/Domino releases do you use? If not the latest, could you try with R8.5.2 ?
jenvinAuthor Commented:
I have got 8.5.1 And all users have 8.5.1 by and large
jenvinAuthor Commented:
Is there a way that we can change the details of the $FILE when the mime content goes beyond a certain size?
Sjef BosmanGroupware ConsultantCommented:
AFAIK, $FILE is and always has been the container for a file, whether using rich-text or MIME. The MIME mails I send are never that big, so I never encountered your problem.

Is there a possibility you give it a try with R8.5.2?

There's one alternative, I think: produce the report as a PDF file and send all files just as attachments.
Sjef BosmanGroupware ConsultantCommented:
Hmm, yeah, right... Pity, though. Maybe the question shouldn't be deleted, as it contains valuable information for the next person struggling with Streams. That's why I object, but don't worry, a Mod will take this over.

@Mods: may I propose a PAQ/Refund?
jenvinAuthor Commented:
For everybody who use mime here are some of my findings

If you have only one mime field in your document (rich text field displaying HTML) then you do not have to worry It will display any amount of content. If you have more than one mime in a document  then make sure that the amount of data in the mime is less than 40k Then each mime field will display the correct data. Beyond that the contents of the mime field  get saved as a $FILE. If there are more than one mime fields with more than 40k data then these $FILE contents are mixed up. I had several mime in my document and I had to put in weeks to understand that it is a bug with Lotus Notes and not a problem with my code. It has nothing to do with Streams as I originally thought. I am using the Stream class to put the long strings into the mime and my thought was that the streams were  not able to store the correct data probably due to the size of the strings and hence the mime was displaying incorrect data. So finally I have concluded that it is not a problem with Streams but a multi mime issue. I now have split the content into smaller chuncks and display that in several mime fields so that it is within the 40k limit
Sjef BosmanGroupware ConsultantCommented:
Thanks for reporting back. :-)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.