Hi. Does anybody have some sample code for inserting file attachments from the local file system into a newly created uidoc?
I am using a dialog box to gather data and at the same time I need to show relevant attachments in this dialog box from the local file system. I can’t seem to find a way to insert attachments using LotusScript via the front end. I know how to do it via the backend tho… any ideas?
Subject: Inserting attachments into uidoc automatically from file system
Here an example… But it crashes after 25times…
Dim session As New NotesSession
Dim db As NotesDatabase
Dim workspace As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument
Dim rtitem As NotesRichTextItem
Dim object As NotesEmbeddedObject
Dim filename As String
Dim ImageType As String
Dim ImageHeight As String
Dim ImageWidth As String
Dim ImageDepth As String
' Open a dialogbox and allow users to select from a list of files
' NB: PNG is missing from here as Notes can't import PNG image types.
Albumname = Inputbox("Bitte geben sie einen Namen für das neue Album ein: ")
files = workspace.OpenFileDialog(True, "File List", "Supported Images|*.jpg;*.bmp;*.gif", "C:\")
If Isempty(files) Then Exit Sub ' Exit if the user selects the Cancel button
Forall FileList In files ' Loop through the list of files selected
Filename = Filelist ' Get the current filename
' GetImageProperties returns an array of ImageType, height, width and bit-depth
imgProps = GetImageProperties(Filename)
ImageType = imgProps(0) ' Get the image type, BMP-GIF-JPEG-PNG
ImageHeight = imgProps(1) ' Get the image height
ImageWidth = imgProps(2) ' Get the image width
ImageDepth = imgProps(3) ' Get the image bit-depth
' Now, we will create a new document and attach the selected image to it.
Set db = session.CurrentDatabase ' Get the current database
Set doc = New NotesDocument( db ) ' Create a new Notes Doc
Set rtitem = New NotesRichTextItem( doc, "Image" ) ' Create a new richtext item
Set object = rtitem.EmbedObject ( EMBED_ATTACHMENT, "", filename) ' Attach the file to it
doc.Form = "ImageSize" ' Set the form name
doc.HEIGHT = Cint(ImageHeight) ' Write the height
doc.Width = Cint(ImageWidth) ' Write the width
doc.colordepth = Cint(ImageDepth) ' Write the colour depth
doc.filesize = Filelen(filename) ' Write the filename
Call doc.Save( True, True ) ' Save the backend document
' Once we have attached the image, we can open the document in the front-end and
' import the same file so we have a preview version.
Set uidoc = workspace.EditDocument( True, doc ) ' Open the backend doc in the UI
Call uidoc.GotoField( "ImageView" ) ' Make the ImageView field the focus
Select Case Imagetype ' Select which image type this file is
Case "GIF":
Call uidoc.Import("GIF Image",filename) ' Import the GIF image into the field
Call uidoc.fieldsettext("ImageType", "GIF Image") ' Set the Image type field
Case "JPEG":
Call uidoc.Import("JPEG Image",filename) ' Import the JPEG image into the field
Call uidoc.fieldsettext("ImageType", "JPEG Image") ' Set the Image type field
Case "PNG":
' NB: This will never happen as Notes doesn't import PNG files although it's there if we need it
Call uidoc.Import("PNG Image",filename) ' Import the PNG image into the field
Call uidoc.fieldsettext("ImageType", "PNG Image") ' Set the Image type field
Case "BMP":
Call uidoc.Import("BMP Image",filename) ' Import the BMP image into the field
Call uidoc.fieldsettext("ImageType", "BMP Image") ' Set the Image type field
End Select
Call uidoc.FieldSetText("Filename", filename) ' Set the filename field
Call uidoc.FieldSetText("Albumtitle", Albumname)
'uidoc.CollapseAllSections ' Collapse the preview section
Call uidoc.save ' Save the UI Doc
Call uidoc.close ' Close the UI Doc
End Forall ' loop through any of the remaining files
Not sure why that code was posted, as it only addresses the original query indirectly, but anyway…
This isn’t a standard function, but some code you can dump in a script library or whatever. GetImageProperties is the typical function name for a load of Lotusscript in the public domain which is based upon David Crowell’s CImageInfo VB routine (http://www.freevbcode.com/ShowCode.Asp?ID=112).
The code allows you to extract certain pieces of key data from an image file (GIF, JPEG, BMP or PNG) such as dimensions and colour depth.
It works pretty well (although PNG image dimensions aren’t always extracted properly). You can find some example code on my site here, but I take no credit for writing this (just cleaned it up and whacked the code in a library):