?
Solved

getting exception when setting NotesRichTextStyle properties

Posted on 2007-08-08
9
Medium Priority
?
1,266 Views
Last Modified: 2013-11-26
with vb.net 2005,
 I am trying to load html into a domino richtextitem to send email,
but the following code snippet throws an exception at the line:

rtstyle.PassThruHTML = True

i have tried

rtstyle.PassThruHTML = -1
to no avail...

I cannot change any property of the NotesRichTextStyle object unless the value is an enumerated Domino value...



Try
            Dim doc As NotesDocument = Me.createDocument(SendTo, _
                                                         subject, _
                                                         nAttachments, _
                                                         AttachmentPaths, _
                                                         CopyTo, _
                                                         BlindCopyTo)

            If doc IsNot Nothing Then
                Dim rtItem As NotesRichTextItem = doc.CreateRichTextItem("Body")
                Dim rtstyle As Domino.NotesRichTextStyle
                rtstyle = mSess.CreateRichTextStyle
'*****************
                rtstyle.PassThruHTML = True '----> always throws exception, unless 0,or 255 (-1 fails, also)
'*****************                
                rtItem.AppendStyle(rtstyle)
                rtItem.AppendText(htmlText)
                doc.Send(False)
            End If

        Catch ex As Exception
            MsgBox("ERROR in Dom.senddoc->" & vbCrLf & ex.Message)
        End Try
0
Comment
Question by:dtrent6396
9 Comments
 
LVL 7

Expert Comment

by:TheNige
ID: 19657603
Is there not an Enumerated value for that property?
0
 

Author Comment

by:dtrent6396
ID: 19657649
thnaks for reponse.
NO here's the Lotus documentation:
Legal values
True (-1) for passthru HTML.
False (0) for non-passthru HTML.
STYLE_NO_CHANGE (255) to maintain the previous state (default).

However, by experimenting I found only 0,1, or 255 will avoid the exception, but setting to 1 is not interpreted as "true" so html is still rendered as raw text
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 19660515
And what is the exception? What's the error you get? There are several possibilities, like rtstyle Is Nothing, or Domino.NotesRichTextStyle isn't compatible with plain NotesRichTextStyle (just guessing).

More info please!
0
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!

 

Author Comment

by:dtrent6396
ID: 19661593
when trying to set any of the properties that take an integer value (such as BOLD, PASSTHRUHTML, ITALICS, UNDERLINE, etc.)  i get this exception:
"Style value must be True, False, or STYLE_NO_CHANGE (YES,NO,or MAYBE for Java) "

Other Properties which have enumerated types (like COLOR, FONTSIZE, EFFECTS) do not throw the exception and produce the desired effect on the text.  
0
 
LVL 22

Expert Comment

by:Bill-Hanson
ID: 19661772
Two things that you need to know:

(1) I find that using late-bound objects rather than importing the "Lotus Domino Objects" reference is easier.  See code example below.

(2) The "Render pass-through HTML in Notes" property the the Memo form is not set by default, so this technique won't work anyway (unless you modify your mail templates).  I've only had success using the MIME classes to send HTML.

Here's a simple function that will do what you asked for (using late-bound objects), but it still won't render as HTML in the Notes client (on the web it will).

    Public Sub SendNotesHtmlMemo(ByVal sendto As String, ByVal subject As String, ByVal body As String)

        Dim sess As Object
        Dim dbMail As Object
        Dim docMemo As Object
        Dim rtItem As Object
        Dim rtstyle As Object

        sess = CreateObject("Notes.NotesSession")
        dbMail = sess.GetDatabase("", "")
        Call dbMail.OpenMail()
        docMemo = dbMail.CreateDocument()
        docMemo.Form = "Memo"
        docMemo.SendTo = sendto
        docMemo.Subject = subject
        rtItem = docMemo.CreateRichTextItem("Body")
        rtstyle = sess.CreateRichTextStyle()
        rtstyle.PassThruHTML = True
        rtItem.AppendStyle(rtstyle)
        rtItem.AppendText(body)
        docMemo.Send(False)

    End Sub

0
 

Author Comment

by:dtrent6396
ID: 19662095
thank you Bill for your response
As you suggested I changed to late binding objects and that does indeed avoid the exception, but , as you said, it doesn't render as html in the email that is produced;

We've been using a program I wrote years ago in VB6 that automates emailing scheduled recurring notices along with attachments.  It has merge capablitilties built into the body of the email that pulls data from Sql Server and Access databases.  I was migrating this program to vb.net and was asked if I could provide "Word-like" formatting to the text body.  So, as first try, i replaced the body text input box with a system.windows.forms.richtextbox. Found that I couldn't paste the richtext into NotesRichTextItem, so when i came across the PassThruHTML flag on the NoteRichTextStyle class, I was thinking that after converting RTF to HTML I could set that flag and be done with it.  RTF to HTML was no problem and with your help I can now set the flag, but alas,  still no Formatting.

All the other formatting properties of the Domino.NotesRichTextStyle class with enumerated types DO affect the way the font is displayed on the email body, so it is very frustrating that the PassThruHtml doesn't render as it does for a web page. What do i need to do to go from Windows RichTextBox to a formatted NoteRichTextItem? Thanks

 

0
 
LVL 22

Accepted Solution

by:
Bill-Hanson earned 2000 total points
ID: 19662202
The richtext classes will not help you.  You need to switch from RichText to MIME.

Try this example:

    Public Sub SendNotesMimeMemo_LateBound(ByVal sendto As String, ByVal subject As String, ByVal body As String)

        Dim sess As Object
        Dim dbMail As Object
        Dim docMemo As Object
        Dim mimeBody As Object
        Dim mimeHtmlPart As Object
        Dim stream As Object
        Dim bConvertMime As Boolean

        Const ENC_QUOTED_PRINTABLE = 1726

        sess = CreateObject("Notes.NotesSession")
        dbMail = sess.GetDatabase("", "")
        Call dbMail.OpenMail()
        docMemo = dbMail.CreateDocument()
        docMemo.Form = "Memo"
        docMemo.SendTo = sendto
        docMemo.Subject = subject

        bConvertMime = sess.ConvertMime
        sess.ConvertMime = False
        stream = sess.CreateStream()
        Call stream.WriteText(body)
        mimeBody = docMemo.CreateMIMEEntity("Body")
        mimeHtmlPart = mimeBody.CreateChildEntity()
        Call mimeHtmlPart.SetContentFromText(stream, "text/html; charset=""iso-8859-1""", ENC_QUOTED_PRINTABLE)
        Call stream.Close()
        sess.ConvertMime = bConvertMime
        Call docMemo.CloseMIMEEntities(True, "Body")

        docMemo.Send(False)

    End Sub
0
 

Author Comment

by:dtrent6396
ID: 19662280
Thank you very much Mr Bill !
Exactly what I was looking for!
Much appreciated and 500 points don't seem enough!
Good Day, sir!


0
 
LVL 22

Expert Comment

by:Bill-Hanson
ID: 19662287
No problem.  Enjoy!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Integration Management Part 2
Loops Section Overview
Suggested Courses

571 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