I'm trying to allow an attachment from an email open in Novell GroupWise to be dropped into my C# WinForms application. The standard .NET functionality doesn't work.
In the DragDrop event of a control, e.Data.GetFormats() returns the following.
FileGroupDescriptorW
FileGroupDescriptor
FileContents
attachment format
I can get the filename with e.Data.GetData("FileGroupDescriptor") and going to position 76.
Unfortunately, e.Data.GetData("FileContents") causes a first chance System.NotImplementedException in System.Windows.Forms.dll and returns null. Attachment format also returns null.
My searches tell me that drag and drop is a lot more complex than I thought :) It seems like GroupWise might be using a format called CFSTR_FILECONTENTS but that's just a guess. The attachments can be successfully dragged and dropped onto the Windows desktop or other folders.
Thanks for any suggestions.
I had no luck finding this too. Here is what I came up with (Groupwise 7):
private void control_DragDrop(object sender, DragEventArgs e)
{
string strFilename = null;
//something about the act of reading this stream creates the file in your temp folder(?)
using (MemoryStream stream = (MemoryStream)e.Data.GetData("attachment format", true))
{
byte[] b = new byte[stream.Length];
stream.Read(b, 0, (int)stream.Length);
strFilename = Encoding.Unicode.GetString(b);
//The path/filename is at position 10.
strFilename = strFilename.Substring(10, strFilename.IndexOf('\0', 10) - 10);
stream.Close();
}
if (strFilename != null && File.Exists(strFilename))
{
//From here on out, you're just reading another file from the disk...
using(FileStream fileIn = File.Open(strFilename, FileMode.Open))
{
//Do your thing
fileIn.Close();
}
}
File.Delete(strFilename);
}