Solved

Save NotesRichtext Field to a rich text file

Posted on 2007-12-04
13
1,734 Views
Last Modified: 2013-12-18
Within Lotus Notes, I wish to save a notesrichtext item out to a richtext formated file that can then be opened in word or other external program.
0
Comment
Question by:tmesias
  • 6
  • 3
  • 2
  • +2
13 Comments
 
LVL 2

Author Comment

by:tmesias
ID: 20406547
btw I wish to do this within Lotus notes on the queryopen or postopen event of a form.  Specifically, I want it to take the "Body" field, which is a richtext type, and output it to a file formatted in the richtext format.
0
 
LVL 22

Expert Comment

by:Bill-Hanson
ID: 20406650
This should get you going.  It's a WIN32 class taken from my own LotusScript library, so it won't work if you just copy and paste it in your project, but all of the details are here.  Use this code as an example and create your own functions that do the same thing.
Declare Public Function W32_ExportRTF Lib "NXRTF" Alias "ExportRTF" (Byval sTempFile As String, Byval flags As Long, hmod As Long, Byval altlibrary As String, Byval sRTFFile As String) As Integer
 

Declare Public Function W32_MailGetMessageBodyComposite Lib "NNOTES" Alias "MailGetMessageBodyComposite" (Byval hNT As Long, Byval N As String, Byval D As String, nD As Long) As Integer
 

'/**

' * Exports richtext to a rich text file that can be opened by WordPad or MS Word.

' */

Public Class RichTextExporter As Win32Class

	

	' Private Data

	Private mDocument As NotesDocument

	Private mItemName As String

	Private mIncludeAttachments As Boolean

	

	'/**

	' * Read-write.  Indicates whether file attachments will be exported.

	' */

	Public Property Get IncludeAttachments As Boolean

		IncludeAttachments = mIncludeAttachments

	End Property

	

	Public Property Set IncludeAttachments As Boolean

		mIncludeAttachments = IncludeAttachments

	End Property

	

	'/**

	' * Attaches the class to an item or document.

	' * If the class is attached to an item, the item is exported.  If the class is attached to a document, the entire document is exported.

	' * @param source A handle to a NotesItem, NotesRichTextItem, or NotesDocument.

	' */

	Public Sub Attach(source As Variant)

		

		If (TRAP_ERRORS) Then On Error Goto CATCH

		Select Case Typename(source)

		Case "NOTESITEM","NOTESRICHTEXTITEM"

			' Attach the exporter to the item.

			Set mDocument = source.Parent

			mItemName = source.Name

		Case "NOTESDOCUMENT"

			' Render the document to a temp item and attach the class to the temp item.

			Dim docTemp As NotesDocument

			Set docTemp = source.ParentDatabase.CreateDocument

			Set mDocument = docTemp

			Dim itmTemp As New NotesRichTextItem(docTemp, "tmp")

			Call source.RenderToRTItem(itmTemp)

			mItemName = itmTemp.Name

		Case Else

			Error ERR_INVALID_PARAM, MSG_ERR_INVALID_PARAM & "Source is not a valid object type."

		End Select

		Exit Sub

		

CATCH:

		Call Me.ThrowError("")

		

	End Sub

	

	'/**

	' * Exports to Rich text format.

	' * @param filePath The full path to the destination file.

	' */

	Public Sub Export(Byval filePath As String)

		

		Dim folderName As String

		Dim cdPath As String

		Dim dirSep As String

		If (TRAP_ERRORS) Then On Error Goto CATCH

		' Ensure the destination folder exists,

		dirSep = StrDirSep("")

		folderName = Trim(Strleftback(filePath, dirSep)) & dirSep

		Call DirCreate(folderName)

		' Export to a cd file.

		cdPath = Me.GetTempFileName()

		Call Me.ExportToCd(cdPath)

		' Convert to an rtf file.

		Call W32_ExportRTF(cdPath, 0, 0, "", filePath)

		' Remove the temp file.

		Kill cdPath

		' Export file attachments.

		If (mIncludeAttachments) Then

			' Extract any files.

			If (mDocument.HasEmbedded) Then

				' Export each file.

				Dim fileItem As NotesRichTextItem

				Set fileItem = mDocument.GetFirstItem(mItemName)

				On Error Resume Next

				Forall fileObject In fileItem.EmbeddedObjects

					Call fileObject.ExtractFile(folderName & fileObject.Name)

				End Forall

				On Error Goto 0

			End If

		End If

		Exit Sub

		

CATCH:

		Call Me.ThrowError("")

		

	End Sub

	

	'/**

	' * Exports to common data format (CD).

	' * @param filePath The full path to the destination file.

	' */

	Private Sub ExportToCd(Byval filePath As String)

		

		Dim fileSize As Long

		Dim contentsPath As String

		Dim fontsPath As String

		If (TRAP_ERRORS) Then On Error Goto CATCH

		' Export contents to a temp file.

		contentsPath = Me.GetTempFileName()

		Call W32_MailGetMessageBodyComposite(mDocument.handle , mItemName, contentsPath, fileSize)

		' Export fonts to a temp file.

		fontsPath = Me.GetTempFileName()

		Call W32_MailGetMessageBodyComposite(mDocument.handle , "$Fonts", fontsPath, fileSize)

		' Concatenate the contents and fonts files.

		Call Me.Concatenate (contentsPath, fontsPath, filePath)

		' Remove temp files.

		Kill contentsPath

		Kill fontsPath

		Exit Sub

		

CATCH:

		Call Me.ThrowError("")

		

	End Sub

	

	'/**

	' * Takes two CD record format files and adds them into one file using binary file access.

	' * @param fileIn1 The full path to the first source file.

	' * @param fileIn2 The full path to the second source file.

	' * @param fileOut1 The full path to the destination file.

	' */

	Private Sub Concatenate(Byval fileIn1 As String, Byval fileIn2 As String, Byval fileOut1 As String)

		

	     ' Note:  There is always an even number of bytes in CD-records so we can use Integers to transfer the data. (Function copied from notes.net.)

		Dim twoBytes As Integer

		Dim fileIn As Integer

		Dim fileOut As Integer

		If (TRAP_ERRORS) Then On Error Goto CATCH

		' Create the destination file.

		fileOut = Freefile 

		Open fileOut1 For Binary As #fileOut

		' Write the first source file to the destination.

		fileIn = Freefile

		Open fileIn1 For Binary As #fileIn

		Do Until Eof (fileIn)

			Get #fileIn,,twoBytes

			Put #fileOut,, twoBytes

		Loop

		Close #fileIn

		' Write the second source file to the destination.

		Open fileIn2 For Binary As #fileIn

		Seek #fileIn, 3 ' First two bytes (one word) of file is control character so this is stripped from second file.

		Do Until Eof (fileIn)

			Get #fileIn,,twoBytes

			Put #fileOut,, twoBytes

		Loop

		Close #fileIn

		Close #fileOut

		Exit Sub

		

CATCH:

		Call Me.ThrowError("")

		

	End Sub

	

	'/**

 	' * Creates a temporary file name.

  	' */

	Private Function GetTempFileName() As String

		

		Dim tempPath As String * 256

		Dim strTempPath As String

		Dim dirSep As String

		If (TRAP_ERRORS) Then On Error Goto CATCH

		dirSep = StrDirSep("")

		Call W32_GetTempPath(256, tempPath)

		strTempPath = Left(tempPath, Instr(tempPath, Chr$(0)) - 1)

		strTempPath = GetLongPathName(strTempPath) & "LsFiles" & dirSep

		Call DirCreate(strTempPath)

		GetTempFileName = strTempPath & StrUnique(True)

		Exit Function

		

CATCH:

		Call Me.ThrowError("")

		

	End Function

	

End Class

Open in new window

0
 
LVL 2

Author Comment

by:tmesias
ID: 20409408
uhmm..  It's going to take me some time time to digest this...  I suppose now I am soul searching as to if I do this from vb.net or really make it a lotus script function...  If I had reference to the UNID of a document...  I wonder if I would be better off exporting with vb.net execting the code vrs notes...  
0
 
LVL 2

Author Comment

by:tmesias
ID: 20409457
let me tell you more of what I am trying to do..   I have a custom application that has it's own custom mail viewer vb.net windows form.  It has two controls, one for Richtext and one for HTML which the user can use to view emails in.  Currently it works with outlook..  the user double clicks on an email and it opens up the email in the application's custom form.  It does this by saving the outlook message out to a temporay file system rich text file that it reads into the rich text control, and by taking the HTMLBODY element exposed by the outlook object model and putting it in the webbrowser control.

Now the user only uses the form to read the mail, if the user decides to do anything with the mail, that is taken care of in the native mail client.  I am only concerned with displaying the contents.

Now I am needing to make this work with Lotus Notes as well.  I have figured out that if I run other custom code I have developed  in the postopen event in lotus notes for the memo, reply, and reply with history forms, that I can save the contents of the opened item out to HTML, which takes care of half of my challange...  Now I am wanting to take the richtext and save it to a file as well...

I am digesting how I can merge your code with my code to say "kill two birds with one stone".   As part of saving the content of the notes email to an HTML file, I save the contents out to a temporary document that has a richtext field.  I am wondering if maybe I do the export to RTF there as I already have a reference to a rtitem.

If you have any further guidence it would be appreciated, otherwise, I am needing to digest all this further before I can say how helpfull the code provided was.
0
 
LVL 22

Expert Comment

by:Bill-Hanson
ID: 20414468
Nope, sorry.

But I have to ask, why?  What is the benefit of writing such an app?  Both Notes and Outlook already have the ability to read and send each other's formats using SMTP/POP.  So if the purpose is to create a client that can view both formats, it's already been done.
0
 
LVL 31

Expert Comment

by:qwaletee
ID: 20414709
Since the Notes "rich text" (compoiund document) format is rather complex, you may be better off "turning this inside out."  Here's what I would consider doing, if your current dialog is rather simple:

1) Develop a tiny Notes database that contains just one form, and that form should mimic your current form.
2) Where your vb.net application currently opens the dialog, have it copy the content to this temporary database, and use Notes.NotesUiWorkspace to have Notes pop up its version of that form

Sound reasonable?

Another way you can do this: I have to look this up, but there is a Notes API you can download that exposes the HTML conversion routines of Notes. You can then use that library to retrieve the HTML content of the message. (Without the additional API, the only ways to get that content in HTML format are to either retrieve it from teh Domino HTTP server, or to have Domino mail the content back out to an SMTP server that you control, or an SMTP mailbox that you control.)
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 2

Author Comment

by:tmesias
ID: 20417743
Ok let me add a little clarification, the vb.net form has more than just those two controls... in fact there are about 25 other controls on the form all which are email-management "gadgets" if you will.  The overall application is a workflow management system.  Primarly these gadgets allow the user the uniquely "stamp" the email with a signature that is embedded in the email text.  They also show additional information for the email...  if the user had previously stamped an email and sent it of by hitting "reply" on the form, the program picks up on that it belongs to a certain collection of emails... and displays any associations with open projects, committments, files, and tasks the user is currently involved in... for instance it will show that the email is about "the burthod case", and here are all the word documents, previous emails, project plans, billing information, etc for "the burthod case".    It even counts how many seconds passed processing the email, which rolls up to being able to bill per email, without making the documentation time for the time spent exceed the time spent... i.e there is no overhead.  suffice this portion of the application is a very sophisticated auto-filling and email processing system that creates auto associations between emails and the user's supporting information.  It gets smarter with each email with advanced algorithims that allow it to "learn" footprints of email threads and content in each email and then suggest to the user a ranking of what that email is likely about, and offer options to then create tasks, project plans, or file the email for reference, all a mouse click away.  Our clients are able to process an outstanding volume of emails without action or information loss using the system.

So back to what I need to be able to do...  on email open, give my program the ability to have a view only, but complete picture of the email... the user is just using this to confirm how this email fit's into the greater scheme of their life and using the gadgetry in the rest of the form to "process" the email.  When they hit reply, stamp, file attachments, etc, the program will then access Lotus Notes via automation and perform the functions, even as far as offering the reply form from notes to the user.  Like I said, I am successful in getting this to work by exporting this to HTML using some ported code I found on the net.  I am wondering if another way to do this would be to use the print function to print an email to a multi page tiff, and then have lotus notes send a message to our program that the file is availilbe and what unid it relates to.
0
 
LVL 2

Author Comment

by:tmesias
ID: 20433032
http://www.codeproject.com/KB/vb/ByPassAutomation.aspx

This will work beautifully.  No translation to HTML, no translation to RTF... nothing....
0
 
LVL 31

Expert Comment

by:qwaletee
ID: 20446577
Hmmm, that IS interesting. Your best bet is definitely the HTML extraction of the message... bearing in mind that you will lose some fidelity, and may want to provide a way to display the mesage in its original format (i.e., to launch the message into Notes).

Personally, I would have designed the app slightly differently. I would have hooked into the Outlook and Notes UIs to detect when a message is opened or sent, and presented the tools as a palette in Outlook or Notes. You get the same functionality, without having to take over all the functions of the messaging agent.
0
 
LVL 2

Author Comment

by:tmesias
ID: 20447678
so far, we are much liking the ability to "lift" the notes window from notes, display it as a child window of our program, an then when we are done with it, return it to notes.  no loss of fidelity, an all the native functionality is there, plus all our gadgets surround the message as required.  This was not an easy task as it required we use the win API to get the right handle for the message, but we have figured out how to on new message open, send a message to our program to go "borrow" the message UI from the new message, and then display it in our program.  We are sill debugging this, but it seems that it will work, plus notes doesn't seem to mind that we "took" the window and "returned" it when we were done.
0
 
LVL 1

Accepted Solution

by:
kodiakbear earned 0 total points
ID: 20521933
A request to delete this question has been asked in the Community Support TA.
If there are no objections from the participating experts this question will be deleted/refund points in 4 days by myself or another moderator.
kb
Experts Exchange Moderator
0
 
LVL 31

Expert Comment

by:qwaletee
ID: 20523294
Deleted? Defdinitely not! If he wants it PAQed and refunded, then sure.
0
 
LVL 1

Expert Comment

by:Computer101
ID: 20539711
Closed, 500 points refunded.
Computer101
EE Admin
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Problem "Can you help me recover my changes?  I double-clicked the attachment, made changes, and then hit Save before closing it.  But when I try to re-open it, my changes are missing!"    Solution This solution opens the Outlook Secure Temp Fold…
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.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

708 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

12 Experts available now in Live!

Get 1:1 Help Now