How to Attach a File to a Rich Text Object

This routine illustrates how to attach a file to a Rich Text field using LotusScript. Using this solution, users can click on an action button and select a file, and the selected file is appended to the predefined Rich Text field on the form.

How It Works

Files can be attached to a Rich Text object using the NotesEmbeddedObject class. First, you must instantiate a NotesEmbeddedObject and a NotesRichTextItem object. Then, using the EmbedObject method, a user can select a file to be attached to the specified NotesRichTextItem field.

Implementation

The following code illustrates how to prompt the user to select a file, attach the file to the Rich Text field called "Body", and email the file to yourself. To implement this solution, create an action button on either a form or view, change the Language Selector to LotusScript, and insert the following code in the Programmer's pane.

 Sub Click(Source As Button)

 '--------------------------------------------------------
 ' Define the objects
 '--------------------------------------------------------
 Dim s As New NotesSession
 Dim w As New NotesUIWorkspace
 Dim db As NotesDatabase
 Dim doc As NotesDocument
 Dim rtitem As NotesRichTextItem
 Dim object As NotesEmbeddedObject
 Dim Person As NotesName
 Dim filename as Variant

 Set s = new NotesSession
 Set w = new NotesUIWorkspace
 Set db = s.CurrentDatabase
 Set doc = New NotesDocument (db)

 '--------------------------------------------------------
 ' Prompt user to select a file.
 '--------------------------------------------------------
 filename = w.OpenFileDialog (True, "Select a file.", , "c:")

 '--------------------------------------------------------
 ' Build the email
 '--------------------------------------------------------
 Set Person = New NotesName

 doc.Form = "Memo"
 doc.SendTo = Person.Abbreviated
 doc.Subject = "Requested File"

 '--------------------------------------------------------
 ' Format the Rich Text field and send email
 '--------------------------------------------------------
 Set rtitem = New NotesRichTextItem(doc, "Body")
 Call rtitem.AddNewline(1)
 Call rtitem.AppendText("Here is the file you requested.")
 Call rtitem.AddNewline (2)
 Set object = rtitem.EmbedObject (EMBED_ATTACHMENT, +_
 "", filename(0))
 doc.Send False
 Msgbox "The requested file has been sent.", 0, "Success"

End Sub



How to Format Text in a Rich Text Object

An Introduction to the Lotus Domino Tool Suite

Getting Started with Designer

Navigating the Domino Designer Workspace

Domino Design Elements

An Introduction to Formula Language

An Introduction to LotusScript

Fundamentals of a Notes Application

Calendar Applications

Collaborative Applications

Reference Library Applications

Workflow Applications

Web Applications

Design Enhancements Using LotusScript

Design Enhancements Using Formula Language

View Enhancements

Sample Agents

Miscellaneous Enhancements and Tips for Domino Databases

Data Management

Security

Application Deployment and Maintenance

Troubleshooting

Appendix A. Online Project Files and Sample Applications

Appendix B. IBM® Lotus® Notes® and Domino®Whats Next?



Lotus Notes Developer's Toolbox(c) Tips for Rapid and Successful Deployment
Lotus Notes Developers Toolbox: Tips for Rapid and Successful Deployment
ISBN: 0132214482
EAN: 2147483647
Year: N/A
Pages: 293
Authors: Mark Elliott

Similar book on Amazon

Flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net