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'.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
richStyle.PassThruHTML = True
Almost the same code would apply for creating just a new paragraph, with the correct style set, to add your HTML.
ASKER
The code example is less than desired because users viewing the document in Notes shows HTML code, not what the browser viewer sees.
ASKER
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.
An additional way would be to use the Midas rich text libraries.
ASKER
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.GetFirstDocumen
While Not(doc Is Nothing)
fileName$ = "C:\Temp\stockspecial6100.
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("WebP
Set rtitem = doc.GetFirstItem( "WebPageContent" )
Set richStyle = session.CreateRichTextStyl
richStyle.PassThruHTML = True
Call rtitem.AppendStyle(richSty
Buffer$ = inStream.ReadText()
Call rtitem.AppendText(Buffer$)
Call inStream.Close
Call doc.Save( False, True )
Set doc = collection.GetNextDocument
Wend
End Sub