Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Notes Stream Question

Posted on 2011-03-03
Medium Priority
Last Modified: 2013-11-17
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?
Question by:jenvin
  • 14
  • 13
  • +1
LVL 22

Expert Comment

ID: 35027777
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?
LVL 46

Expert Comment

by:Sjef Bosman
ID: 35028790
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.

Author Comment

ID: 35029426
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?
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 46

Expert Comment

by:Sjef Bosman
ID: 35029522
It's called "set content from text", and not "add content"...

Can you show us the essential lines of the code you're testing?

Author Comment

ID: 35029763
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?
LVL 46

Expert Comment

by:Sjef Bosman
ID: 35031727
2 Gb ??

See http://publib.boulder.ibm.com/infocenter/domhelp/v8r0/index.jsp?topic=/com.ibm.designer.domino.main.doc/H_READTEXT_METHOD_STREAM.html

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...

Author Comment

ID: 35033993
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

LVL 46

Expert Comment

by:Sjef Bosman
ID: 35034356
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

Author Comment

ID: 35035001
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
LVL 46

Expert Comment

by:Sjef Bosman
ID: 35035639
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?

Author Comment

ID: 35035675
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?
LVL 46

Expert Comment

by:Sjef Bosman
ID: 35035768
Check here for Notes limits: http://www.thenorth.com/northern.nsf/ac567d6535ab069785256a00004d66dc/4100857248b8b82185256d350058f7e4!OpenDocument

64Kb per paragraph, 64K paragraphs in total, hence 2^32 = 4Gb bytes maximum.

Author Comment

ID: 35035968
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?

Author Comment

ID: 35036155
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

LVL 46

Expert Comment

by:Sjef Bosman
ID: 35036369
It is simply stream0.Bytes

Author Comment

ID: 35036410
Sowhen the complete table does not display it is 286462 bytes? Please help I am struggling since 2 days!!!!
LVL 46

Expert Comment

by:Sjef Bosman
ID: 35037028
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!

Author Comment

ID: 35037369
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 i.name = "$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
LVL 46

Expert Comment

by:Sjef Bosman
ID: 35037541
$FILE items are attached files, usually attached to a rich-text item. Are you copying complete rich-text items??

Author Comment

ID: 35090230
My issue has not been resolved yet. Please help me to create and read MIME_PArt. The content is just text/Html
LVL 46

Expert Comment

by:Sjef Bosman
ID: 35135753
By the way, which Notes/Domino releases do you use? If not the latest, could you try with R8.5.2 ?

Author Comment

ID: 35136091
I have got 8.5.1 And all users have 8.5.1 by and large

Author Comment

ID: 35136095
Is there a way that we can change the details of the $FILE when the mime content goes beyond a certain size?
LVL 46

Expert Comment

by:Sjef Bosman
ID: 35136223
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.
LVL 46

Expert Comment

by:Sjef Bosman
ID: 35187666
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?

Accepted Solution

ee_auto earned 0 total points
ID: 35225514
Question PAQ'd and stored in the solution database.

Author Comment

ID: 35259183
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
LVL 46

Expert Comment

by:Sjef Bosman
ID: 35261067
Thanks for reporting back. :-)

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For users on the Lotus Notes 8 Standard client, this article provides information on checking the Java Heap size and adjusting it to half of your system RAM in attempt to get the Lotus Notes 8.x Standard client to run faster.  I've had to exercise t…
Article by: Rob
Notes 8.5 Archiving Steps and Tips This article covers setting up a Notes archive, and helps understand some of the menu choices making setting up and maintaining a Notes archive file easier.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question