Drag&drop an EMail-Attachment (PDF) from Outlook to copy (with WindowsDropTargetMBS)

Hello!

I want to drag the pdf attachment from an Outlook mail window into my app window to copy the attached pdf file to the C:\TEMP folder. I tried to do this with the help of the MBS Win plugin (WindowsDropTargetMBS).
I compiled the example “Attachment Drop from Outlook” from the MBS examples. When I drag the pdf onto the window, I get some informations. But the method .GetPaths always seems to returns nothing. With the method .GetFileContents I get the filename of my pdf file, but I am not able to copy the file to the wanted location.

Is there somebody who can help to show me what I am doing wrong?

(Using Xojo 2025 R2 on MacBook Air M3, MBS Plugins 25.3, Windows 11, Office 365)

FileDropWindow.List.RemoveAllRows
FileDropWindow.List.AddRow "Formats: " + Join(dataObject.Formats, ", ")

If allowed Then
  // allow it
  effect = DROPEFFECT_COPY
  
  Var files(-1) As FolderItem = dataObject.GetPaths
  
  For Each f As FolderItem In files
    // we got a file you can use like any other file (e.g. copy)
    //
    // this NEVER happens! Seems that .GetPaths does not work
    // the code to copy the file should be here...
    FileDropWindow.List.AddRow "Path """ + f.NativePath + """"
  Next
  
  Var des(-1) As WindowsFileDescriptorMBS = dataObject.GetFileDescriptors
  
  For Each d As WindowsFileDescriptorMBS In des
    // we got file descriptions. Some metadata and the data. No path.
    //
    // This works...
    Var data As String = dataObject.GetFileContents(d.Index)
    
    FileDropWindow.List.AddRow "File """ + d.FileName + """ with " + data.Length.ToString + " bytes data."
    FileDropWindow.List.AddRow "ClassID: " + d.ClassID
    FileDropWindow.List.AddRow "Flags: " + d.Flags.ToString
    FileDropWindow.List.AddRow "FileAttributes: " + d.FileAttributes.ToString
    
  Next
 

Well, a WindowsFileDescriptorMBS can contain

  • data, which is delivered on demand
  • a file path

With outlook, you get the descriptor and when you ask for data, it may ask Outlook internally to provide it on demand.

When you call:
GetFileContents(index as integer, byref IsPath as boolean) as string

the plugin may return data directly or the path here.

Thank you for your answer. So I have to make/save a file from the string I got from .GetfileContents(index), .GetPaths is not the way to go…

Solution found. I have to encode the string from GetFileContents() and write it to disk like this:

For Each d As WindowsFileDescriptorMBS In des
  // we got file descriptions. Some metadata and the data. No path.
  Var data As String = EncodeBase64(dataObject.GetFileContents(d.Index))

  Var pdffile As FolderItem = New FolderItem("C:\TEMP")
  pdffile = pdffile.Child(d.FileName)

  DataToPDF(data, pdffile)

Here the little write function:

Function DataToPDF(FileContent As String, f As FolderItem)
  Var encoded_data As New MemoryBlock(FileContent.Length)
  encoded_data = DecodeBase64(FileContent)

  Var mybs As BinaryStream = BinaryStream.Create(f, True)
  mybs.Write(encoded_data)

  mybs.Close
End function