Agent to Import HTML file into a rich text field.

Posted on 2007-07-31
Last Modified: 2013-12-18
I use the Excell Publish feature to create an HTML file, and I want to use an agent to the import files into rich text field in a document in a Notes database.   I use the term 'import' because I know I can do File Import as a user, and I can create a button for the user to press which does the 'import' process which is available as a method under notesUIDocument.   But, I can't find a way to do the import as an agent which could be run in batch to update a group of documents with the appropriate HTML files.  The database is published to the web and these documents are normally viewed by a browser.
I have found an approximation by using Stream and bringing the text into the field.  With passthru HTML turned on the field is correct when viewed with a browser.  But the HTML code is seen when the document is viewed with the Notes client.  I would rather have the action of 'import'.
Question by:Charlie Neumann
    LVL 22

    Accepted Solution

    There is no backend support for the ui "import" feature.  Like you, I've had limited success using pass-thru html, so I decided to try my hand at loading HTML into RichText fields as MIME.  It has been working good for me so far, but I've only been working with simple text formatting and images.  If you're interested, take a look at the NotesMimeXXX classes.

    Author Comment

    by:Charlie Neumann
    I looked at MIME but I'm working with an existing form design where the field name is 'WebPageContent'.  It appears that only choice with MIME would be to create a new item in the document.  I would have to delete the existing rich text field and recreate it as a MIME entity.  I wanted to avoid that for other reasons.  We'll see if MIME is the only way to go.

    For reference;   This is the basics of the code which I use for what is approximately working now;

    LotusScript Code:
    Option Public
    Dim fileNum As Integer
    Dim fileName As String
    Dim inrec As Variant
    Dim doc As NotesDocument
    Dim rtitem As NotesRichTextItem
    Dim db As NotesDatabase
    Dim collection As NotesDocumentCollection
    Dim inStream As NotesStream
    Dim item As NotesItem
    Dim richStyle As NotesRichTextStyle
    ' Developer note:
    '  " WebPageContent" is an existing field in the form.
    '  The hard coded fileName$ should be replaced by a string value from the form.
    Sub Initialize
          Dim session As New NotesSession
          Set db = session.CurrentDatabase
          Set collection = db.UnprocessedDocuments
          Set doc = collection.GetFirstDocument()
          While Not(doc Is Nothing)
                fileName$ = "C:\Temp\stockspecial6100.htm"
                Set inStream = session.CreateStream
                If Not inStream.Open(fileName, "ASCII") Then
                      Messagebox fileName,, "Open failed"
                      Exit Sub
                End If
                If inStream.Bytes = 0 Then
                      Messagebox fileName,, "File has no content"
                      Exit Sub
                End If
                Set item = Doc.ReplaceItemValue("WebPageContent","")
                Set rtitem = doc.GetFirstItem( "WebPageContent" )
                Set richStyle = session.CreateRichTextStyle
                richStyle.PassThruHTML = True
                Call rtitem.AppendStyle(richStyle)
                Buffer$ = inStream.ReadText()
                Call rtitem.AppendText(Buffer$)
                Call inStream.Close
                Call doc.Save( False, True )
                Set doc = collection.GetNextDocument(doc)
    End Sub
    LVL 46

    Expert Comment

    by:Sjef Bosman
    The essential line in the code is
                richStyle.PassThruHTML = True

    Almost the same code would apply for creating just a new paragraph, with the correct style set, to add your HTML.

    Author Comment

    by:Charlie Neumann
    The code example is less than desired because users viewing the document in Notes shows HTML code, not what the browser viewer sees.

    Author Comment

    by:Charlie Neumann
    I'm pleased to learn that I had found the only viable solution.  Thanks for the response.  Apparently it was as difficult as I thought.
    LVL 31

    Expert Comment

    There is another solution, but it is quite complicated.  It is possible to transform XHTML into DXL and import it.

    An additional way would be to use the Midas rich text libraries.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    IBM Notes offer Encryption feature using which the user can secure its NSF emails or entire database easily. In this section we will discuss about the process to Encrypt Incoming and Outgoing Mails in depth.
    Notes Document Link used by IBM Notes is a link file which aids in the sharing of links to documents in email and webpages. The posts describe the importance and steps to create a Lotus Notes NDL file in brief.
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    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…

    754 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

    22 Experts available now in Live!

    Get 1:1 Help Now