Sub ExtractImageResources(db As NotesDatabase, DestinationDirectory As String) ' ========================================================= ' Extracts all GIF and JPG image resource file to ' DestinationDirectory must exist. ' This code creates 2 tempfiles in dest. directory. ' Guess it will be possible to do it without tempfiles... feel free to try ' ========================================================= 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 Base64Tempfile 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 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" Base64Tempfile= DestinationDir & "tmp_image.b64" ' ======================== ' 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 tempfile 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 ' Write base64 image date to a tempfile If debug=1 Then Print "Writing " & Base64Tempfile On Error Resume Next Kill (Base64Tempfile) On Error Goto err1 Set stream = session.CreateStream Call stream.Open( Base64Tempfile ,"UTF-8") Call stream.WriteText( TempChildNode.NodeValue, EOL_NONE) Call stream.Close ' ==================================================== ' Convert base64 tempfile into a binary file with image's filename ' ==================================================== If debug = 1 Then Print "Reading " & Base64Tempfile Dim doc As NotesDocument Set doc = New NotesDocument( db ) Set Stream = session.CreateStream Call Stream.Open( Base64Tempfile, "binary") Set outStream = session.CreateStream If debug = 1 Then Print "Creating " & DestinationDir & IRFilename On Error Resume Next Kill (DestinationDir & IRFilename) On Error Goto err1 Call outStream.Open( DestinationDir & IRFilename, "binary") ' Read base64 tempfile file and decode If debug=1 Then Print "Decoding Base64 to binary" Set MimeEntity = doc.CreateMIMEEntity Call MIMEEntity.SetContentFromBytes( stream, "", ENC_BASE64) Call MimeEntity.DEcodeContent() ' Write to outstream If debug=1 Then Print "Writing " & DestinationDir & IRFilename Call MIMEEntity.GetContentAsBytes( outstream, False) Call Stream.Close Call outstream.Close End If End If Next n1 Call inputstream.close finish: If debug=1 Then Print "Removing tempfiles" On Error Resume Next Kill( Base64Tempfile) Kill( DXLTempfile) On Error Goto err1 Print Exit Sub err1: Print Error$ & " in line " & Erl Messagebox Error$ & " in line " & Erl Exit Sub End Sub