Link to home
Start Free TrialLog in
Avatar of Charlie Neumann
Charlie Neumann

asked on

Agent to Import HTML file into a rich text field.

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'.
ASKER CERTIFIED SOLUTION
Avatar of Bill-Hanson
Bill-Hanson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Charlie Neumann
Charlie Neumann

ASKER

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)
      Wend
End Sub
      
Avatar of 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.
The code example is less than desired because users viewing the document in Notes shows HTML code, not what the browser viewer sees.
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.
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.