Sub ExtractImageResources(db As NotesDatabase, DestinationDirectory As String) ' ========================================================= ' Extracts all GIF and JPG image resource file to ' DestinationDirectory must exist. ' This code creates 1 tempfile in dest. directory. ' ========================================================= Dim session As New NotesSession Dim DestinationDir As String Dim debug As Integer Dim nc As NotesNoteCollection Dim exporter As NotesDXLExporter Dim stream As NotesStream Dim DXLTempfile As String Dim inputStream As NotesStream Dim domParser As NotesDOMParser Dim RootNode As NotesDOMDocumentNode Dim n1 As Integer Dim i As Integer Dim ImageResource_Nodes As notesDOMNodeList Dim MyNode As NotesDOMElementNode Dim TempNode As NotesDOMElementNode Dim TempChildNode As NotesDOMNode Dim MyNodeList As notesDOMNodeList Dim attr As notesDOMAttributeNode Dim IRFilename As String Dim MimeEntity As NotesMimeEntity Dim outStream As NotesStream Dim doc As NotesDocument On Error Goto err1 debug = 1 ' set to 0 for no debg output DestinationDir = Trim$(DestinationDirectory) If Right$( DestinationDir, 1)<>"\" Then DestinationDir = DestinationDir+"\" ' ==================================================== ' Define tempfiles - if you manage to make the DXL export/import ' work without tempfiles, let me know ! ' ===================================================== DXLTempfile = DestinationDir & "tmp_fileresources.dxl" ' ======================== ' Create DXL export stream ' ======================== On Error Resume Next Kill( DXLTempfile) On Error Goto err1 Set stream = session.CreateStream If Not stream.Open( DXLTempfile,"UTF-8") Then Messagebox "Cannot create " & DXLTempfile,, "Error" Exit Sub End If Call stream.Truncate ' =============================== ' Build collection of design elements ' =============================== If debug = 1 Then Print "Building design note document collection" Set nc = db.CreateNoteCollection(False) Call nc.SelectAllFormatElements(False) nc.SelectImageResources = True Call nc.BuildCollection ' ================================ ' Export DesignNoteCollection as DXL ' ================================ If debug = 1 Then Print "Exporting image resources to " & DXLTempfile Set exporter = session.CreateDXLExporter(nc, stream) Call exporter.Process Call stream.Close ' ========================= ' Import DXL for parsing ' ========================= If debug = 1 Then Print "Creating DXL import stream from " & DXLTempfile Set inputStream = session.CreateStream Call inputStream.Open ( DXLTempfile ,"UTF-8") ' ========================= ' Parse DXL ' ========================= Print "Parsing DXL" Set domParser=session.CreateDOMParser(inputStream) domParser.Process ' ======================= ' Get the root node ' ====================== Set rootNode = domParser.Document ' ========================= ' Get all ImageResourceNodes ' ========================= Set ImageResource_Nodes = RootNode.GetElementsByTagName( "imageresource" ) If debug=1 Then Print "Found " & ImageResource_Nodes.NumberOfEntries & " image resources" If ImageResource_Nodes.NumberOfEntries=0 Then Print "No node found - exiting" Goto finish End If ' ============================================= ' Browse all nodes and extract images ' from / child nodes ' ============================================= For n1 = 1 To ImageResource_Nodes.NumberOfEntries If debug = 1 Then Print "Processing Image Resource " & n1 Set MyNode = ImageResource_Nodes.GetItem( n1 ) ' Get the filename from "" node For i = 1 To MyNode.Attributes.NumberOfEntries Set attr = MyNode.Attributes.GetItem(i) If attr.NodeName="name" Then IRFilename = attr.NodeValue Exit For End If Next i ' Get the or node Set MyNodeList = MyNode.GetElementsByTagName( "gif" ) If MyNodeList.NumberOfEntries =0 Then Set MyNodeList = MyNode.GetElementsByTagName( "jpeg" ) End If ' Now get the base64 encoded image data from the child (textnode) and write it to disk If Not MyNodeList Is Nothing Then If MyNodeList.NumberOfEntries > 0 Then Set TempNode = MyNodeList.GetItem(1) Set TempChildNode = tempNode.firstchild ' TempChild.NodeValue contains the base64 encoded image data ' Create output stream / file If debug=1 Then Print "Create output file " & DestinationDir & IRFilename Set outStream = session.CreateStream On Error Resume Next Kill (DestinationDir & IRFilename) On Error Goto err1 Call outStream.Open( DestinationDir & IRFilename, "binary") ' Create Input Stream and write Base64 data to stream Set stream = session.CreateStream Call stream.WriteText( tempchildNode.NodeValue ) ' Decode base64 and write to outstream / file If debug=1 Then Print "Decoding Base64 to binary" Set doc = New NotesDocument( session.CurrentDatabase ) Set MimeEntity = doc.CreateMIMEEntity Call MimeEntity.SetContentFromBytes( stream, "", ENC_BASE64) Call MimeEntity.GetContentAsBytes(outStream, True) Call MimeEntity.DEcodeContent() Call outstream.Close Call stream.close End If End If Next n1 Call inputstream.close finish: If debug=1 Then Print "Removing tempfiles" On Error Resume Next Kill( DXLTempfile) On Error Goto err1 Print Exit Sub err1: Print Error$ & " in line " & Erl Messagebox Error$ & " in line " & Erl Exit Sub End Sub