Solved

Notes Stream Question

Posted on 2011-03-03
30
2,860 Views
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?
0
Comment
Question by:jenvin
  • 14
  • 13
  • +1
30 Comments
 
LVL 22

Expert Comment

by:mbonaci
Comment Utility
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:

http://publib.boulder.ibm.com/infocenter/domhelp/v8r0/topic/com.ibm.designer.domino.main.doc/H_SETCONTENTFROMTEXT_METHOD_MIMEENTITY.html

Have you set s.ConvertMIME to False before creating MIMEEntity, to avoid converting MIME to rich text?
0
 
LVL 46

Expert Comment

by:Sjef Bosman
Comment Utility
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.
0
 

Author Comment

by:jenvin
Comment Utility
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
      Stream.WriteText(Stream2.readtext)
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?
0
 
LVL 46

Expert Comment

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

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

Author Comment

by:jenvin
Comment Utility
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?
0
 
LVL 46

Expert Comment

by:Sjef Bosman
Comment Utility
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...
0
 

Author Comment

by:jenvin
Comment Utility
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
	Else
		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
	Else
		
		firstSet = Round(NumOfResp/2, 0)
		secondSet = NumOfResp - firstSet
	End If
	
	Set responsedoc = Collection.getfirstDocument
	k=1
	'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))
		Else
			Call AddMainlineAdders(FieldNames(2))
		End If
		
		Call EngStatusSummary(FieldNames(3))
		Call AddTAT(FieldNames(4))
		
		k=k+1
		Set responseDoc = collection.GetNextDocument(responseDoc)
	'	Set responseDoc = collection.GetNthDocument(k)
		
	Loop
nextSteps:
	' set the values in the drr document
	
	'set solution
	Call AddSolFooter
'	Stream0.WriteText("</table>")
	Stream5.WriteText("</table>")
	
	
	Stream5.Position =0
	Stream0.WriteText(Stream5.readtext)
	
	'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.WriteText("</table>")
	'Stream1.Position = 0
	Stream6.WriteText("</table>")
	Stream6.Position = 0
	Stream1.WriteText(Stream6.ReadText)
	
	
	
	
	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
	'Stream2.WriteText("</table>")
	Stream7.WriteText("</table>")
	Stream7.position =0
	Stream2.WriteText(Stream7.readtext)
	'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
	'Stream3.WriteText("</table>")
	
	
	
	
	Stream8.WriteText("</table>")
	Stream8.position =0
	Stream3.WriteText(Stream8.readtext)
	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.WriteText("</table>")
	Stream9.Position = 0
	Stream4.WriteText(Stream9.readtext)
	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
	
InitializeError:
	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

0
 
LVL 46

Expert Comment

by:Sjef Bosman
Comment Utility
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
      streamx.WriteText(streamy.ReadText)
0
 

Author Comment

by:jenvin
Comment Utility
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
0
 
LVL 46

Expert Comment

by:Sjef Bosman
Comment Utility
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?
0
 

Author Comment

by:jenvin
Comment Utility
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?
0
 
LVL 46

Expert Comment

by:Sjef Bosman
Comment Utility
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.
0
 

Author Comment

by:jenvin
Comment Utility
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?
0
 

Author Comment

by:jenvin
Comment Utility
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

0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 46

Expert Comment

by:Sjef Bosman
Comment Utility
It is simply stream0.Bytes
0
 

Author Comment

by:jenvin
Comment Utility
Sowhen the complete table does not display it is 286462 bytes? Please help I am struggling since 2 days!!!!
0
 
LVL 46

Expert Comment

by:Sjef Bosman
Comment Utility
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!
0
 

Author Comment

by:jenvin
Comment Utility
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
0
 
LVL 46

Expert Comment

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

Author Comment

by:jenvin
Comment Utility
My issue has not been resolved yet. Please help me to create and read MIME_PArt. The content is just text/Html
0
 

Author Comment

by:jenvin
Comment Utility
0
 
LVL 46

Expert Comment

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

Author Comment

by:jenvin
Comment Utility
I have got 8.5.1 And all users have 8.5.1 by and large
0
 

Author Comment

by:jenvin
Comment Utility
Is there a way that we can change the details of the $FILE when the mime content goes beyond a certain size?
0
 
LVL 46

Expert Comment

by:Sjef Bosman
Comment Utility
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.
0
 
LVL 46

Expert Comment

by:Sjef Bosman
Comment Utility
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?
0
 

Accepted Solution

by:
ee_auto earned 0 total points
Comment Utility
Question PAQ'd and stored in the solution database.
0
 

Author Comment

by:jenvin
Comment Utility
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
0
 
LVL 46

Expert Comment

by:Sjef Bosman
Comment Utility
Thanks for reporting back. :-)
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This is an old article, please see an updated version of this article, located here: http://www.experts-exchange.com/articles/23619/Notes-8-5x-Windows-7-Notes-info-and-tips.html
  In today’s Arena we can’t imagine our lives without Internet as we are highly used to of it. If we consider our life style just for only 2 min we found that face to face communication is swapped by e-communication.  Every Where from Works place to…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now