1

I'm trying to get multiple Outlook attachments from the clipboard.

When a user chooses multiple attachments and places them in the clipboard (or drag them), an IDataObject is being created and is being placed in the clipboard.

I know that the file names can be found in the IDataObject using CLIPFORMAT CFSTR_FILEDESCRIPTOR that contains the virtual object names. Also, I from what I understand, the file content is being received using CLIPFORMAT CFSTR_FILECONTENTS. But when I do that, I get only one file, and I don't understand how do I get the other files that have been copied to the clipboard.

I found that using the lindex member in FORMATETC I can get the other files, but for some reason it doesn't work.

Can anyone explain or give an example how can I get the other attachments (prefering C++)?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
TCS
  • 5,790
  • 5
  • 54
  • 86

1 Answers1

0

Take a look at the CodeProject Outlook Drag-n-Drop example. It uses IDataObject in a wrapper class OutlookDataObject, but it is the same interface used by the Clipboard. In C#, you could do the following...

// IDataObject wrapper
OutlookDataObject dataObject = new OutlookDataObject(Clipboard.GetDataObject());

// retrieving filenames
string[] filenames = (string[])dataObject.GetData("FileGroupDescriptorW");
this.label1.Text = "filenames:\n    " + string.Join(",", filenames) + "\n";

// writing out file contents
MemoryStream[] filestreams = (MemoryStream[])dataObject.GetData("FileContents");

this.label1.Text += "Files:\n";
for (int fileIndex = 0; fileIndex < filenames.Length; fileIndex++)
{
    //use the fileindex to get the name and data stream
    string filename = filenames[fileIndex];
    MemoryStream filestream = filestreams[fileIndex];
    this.label1.Text += "    " + filename + "\n";

    //save the file stream using its name to the application path
    FileStream outputStream = File.Create(filename);
    filestream.WriteTo(outputStream);
    outputStream.Close();
}

Looking at the OutlookDataObject wrapper class, you should be able to implement something similar in C++.

SliverNinja - MSFT
  • 31,051
  • 11
  • 110
  • 173