drag email to custom .net application

Hallo,

I would like to drag a em-Client email by drag and drop in my .net application. Unfortunally

the standard drag drop behavior which work well with MS Outlook doesnt work with eM client.

In opposition to MS Outook which works with a System.Windows.Forms.DataObject in the drag-drop container your em-Client works with a System.Com.Object.

Do you have a drag-drop sample-project or code?

Here my code:

private void listView1_DragOver(object sender, DragEventArgs e)
    {
      try
      {
        if (e.Data.GetDataPresent(DataFormats.FileDrop))
        {
          e.Effect = DragDropEffects.All;
          return;
        }
        if (e.Data.GetDataPresent(“FileGroupDescriptor”))
        {
          e.Effect = DragDropEffects.All;
          return;
        }
        e.Effect = DragDropEffects.None;
        return;

      }
      catch (Exception ex)
      {
        MessageBox.Show(ex.Message);
      }

    }

    private void listView1_DragDrop(object sender, DragEventArgs e)
    {
      string[] FileNames = null;
      FileNames = (string[])e.Data.GetData(DataFormats.FileDrop);

      if (FileNames != null)
      {
        //foreach (string file in FileNames)
          //uploadDocument(file);

        //getDocumentList();
        return;
      }
    }

Hello, you cannot use DataFormats.FileDrop simply because during the drag-drop operation there is no temporary file created - all the data is stored only in memory.

The option how to get the content being dragged is using the ‘FileGroupDescriptor’ or ‘FileGroupDescriptorW’

a very simplified code could look like this:

if (e.Data.GetDataPresent(“FileGroupDescriptor”) || e.Data.GetDataPresent(“FileGroupDescriptorW”)
{
MemoryStream stream = e.Data.GetData(“FileContents”) as MemoryStream;
if (stream != null)
{
// here you get a memory stream of the mail being dragged
// this way you get only the stream of the first item, for the rest, use e.Data.GetData(“FileContents”, index) method
}
}

hello,

thank for information! After I have modifi my code it works till e.Data.GetData(“FileContents”. Problem ist that des the stream Obj is allways null. When I Loop through all data / formats of the e.Data object I saw the FileContents is contained but it is null…

here my code:

    private void listView1_DragDrop(object sender, DragEventArgs e)
    {
      try
      {
        if (e.Data.GetDataPresent(DataFormats.FileDrop))
        {
          string[] FileNames = null;
          FileNames = (string[])e.Data.GetData(DataFormats.FileDrop);

          if (FileNames != null)
          {
            //foreach (string file in FileNames)
            //uploadDocument(file);

            //getDocumentList();
            return;
          }
        }
        else if (e.Data.GetDataPresent(“FileGroupDescriptor”) || e.Data.GetDataPresent(“FileGroupDescriptorW”))
        {
          System.Console.WriteLine("— Start Drop -----------------");

          foreach (string curFormatName in e.Data.GetFormats())
          {

            MemoryStream stream = e.Data.GetData(curFormatName, true) as MemoryStream;
            object obj = e.Data.GetData(curFormatName, true);

            // output
            System.Console.WriteLine(string.Format(“Name: {0}”, curFormatName));

            if ( obj == null)
              System.Console.WriteLine(string.Format(“Value: {0}”, “null”));
            else
              System.Console.WriteLine(string.Format(“Value: {0}”, obj.GetType()));
           
            if (stream != null)
            {
              MessageBox.Show(“hit”);
              // here you get a memory stream of the mail being dragged
              // this way you get only the stream of the first item, for the rest, use e.Data.GetData(“FileContents”, index) method
            }
          }

          System.Console.WriteLine("— Stop Drop -----------------");       
        }
      }

      catch (Exception ex)
      {
        MessageBox.Show(ex.Message);
      }
    }             

the output of one drop event:

— Start Drop -----------------
Name: MailItems
Value: System.__ComObject
Name: FileGroupDescriptorW
Value: System.MarshalByRefObject
Name: FileContents
Value: null
Name: UnicodeText
Value: System.MarshalByRefObject
Name: Text
Value: System.MarshalByRefObject
Name: HTML Format
Value: System.MarshalByRefObject
Name: IsShowingLayered
Value: System.MarshalByRefObject
Name: IsShowingText
Value: System.MarshalByRefObject
— Stop Drop -----------------

Did you have any idea? I can`t not recognition the reason of my problem.

best regards

sascha

Hello again,

I wasn’t completely right in my previous answer, because I didn’t remember the implementation details. You need the reverse way of the technique described here http://www.codeproject.com/Articles/2…
It doesn’t seem to be an easy task and unfortunately I cannot provide you any sample code for this - simply because I don’t have any

Hello again,

thank for Informations. I try to get drag drop container Information by thiscode:

private void listView1_DragDrop(object sender, DragEventArgs e)
    {
      try
      {
        if (e.Data.GetDataPresent(DataFormats.FileDrop))
        {
          string[] FileNames = null;
          FileNames = (string[])e.Data.GetData(DataFormats.FileDrop);

          if (FileNames != null)
          {
            //foreach (string file in FileNames)
            //uploadDocument(file);

            //getDocumentList();
            return;
          }
        }
        else if (e.Data.GetDataPresent(“FileGroupDescriptor”) || e.Data.GetDataPresent(“FileGroupDescriptorW”))
        {

          /// Variables
          System.Windows.Forms.IDataObject underlyingDataObject;
          System.Runtime.InteropServices.ComTypes.IDataObject comUnderlyingDataObject;
          System.Windows.Forms.IDataObject oleUnderlyingDataObject;
          MethodInfo getDataFromHGLOBLALMethod;

          //get the underlying dataobject and its ComType IDataObject interface to it
          underlyingDataObject = e.Data;
          comUnderlyingDataObject = (System.Runtime.InteropServices.ComTypes.IDataObject)underlyingDataObject;

          //get the internal ole dataobject and its GetDataFromHGLOBLAL so it can be called later
          FieldInfo innerDataField = underlyingDataObject.GetType().GetField(“innerData”, BindingFlags.NonPublic | BindingFlags.Instance); /// OUTLOOK have a “innerData” Field

          if (innerDataField == null)
            innerDataField = underlyingDataObject.GetType().GetField(“m_ObjectToDataMap”, BindingFlags.NonPublic | BindingFlags.Instance); /// EM-CLIENT have NO “innerData” Field only “m_ObjectToDataMap” Field

          oleUnderlyingDataObject = (System.Windows.Forms.IDataObject)innerDataField.GetValue(underlyingDataObject);
          getDataFromHGLOBLALMethod = oleUnderlyingDataObject.GetType().GetMethod(“GetDataFromHGLOBLAL”, BindingFlags.NonPublic | BindingFlags.Instance);

          //get the names and data streams of the files dropped
          //string[] filenames = (string[])dataObject.GetData(“FileGroupDescriptorW”);
          //MemoryStream[] filestreams = (MemoryStream[])dataObject.GetData(“FileContents”);
        }       
      }

      catch (Exception ex)
      {
        MessageBox.Show(ex.Message);
      }
    }

As against to MS Outlook the EM-Client DragDrop-Container doesn’t have a field “innerData”. The innerdata-field of the MS Outlook Container contains the infos of the dragging email. The EM-Client contains only a field “m_ObjectToDataMap”. Unfortunaly the value of this field is null. It must exist a a way to get the data of your DragDrop-Container but it is possibel to drag a EM Email to MS Outlook or to files system. Did you have any idea?

Members of ECleint DragDrop Container

GetIUnknown
GetData
SetData
ReleaseAllData
GetEventProvider
ReleaseSelf
FinalReleaseSelf
CreateEventProvider
GetComIUnknown
IsInstanceOfType
InvokeMember
MemberwiseClone
__RaceSetServerIdentity
__ResetServerIdentity
CanCastToXmlType
Finalize
MemberwiseClone
.ctor
m_ObjectToDataMap

Members of MS Outlool DragDrop Container

get_RestrictedFormats
set_RestrictedFormats
System.Runtime.InteropServices.ComTypes.IDataObject.DAdvise
System.Runtime.InteropServices.ComTypes.IDataObject.DUnadvise
System.Runtime.InteropServices.ComTypes.IDataObject.EnumDAdvise
System.Runtime.InteropServices.ComTypes.IDataObject.EnumFormatEtc
System.Runtime.InteropServices.ComTypes.IDataObject.GetCanonicalFormatEtc
System.Runtime.InteropServices.ComTypes.IDataObject.GetData
System.Runtime.InteropServices.ComTypes.IDataObject.GetDataHere
System.Runtime.InteropServices.ComTypes.IDataObject.QueryGetData
System.Runtime.InteropServices.ComTypes.IDataObject.SetData
GetCompatibleBitmap
GetTymedUseable
GetDataIntoOleStructs
SaveDataToHandle
SaveObjectToHandle
SaveStreamToHandle
SaveFileListToHandle
SaveStringToHandle
SaveHtmlToHandle
Finalize
MemberwiseClone
.ctor
.ctor
RestrictedFormats
innerData
k__BackingField
FormatEnumerator
OleConverter
DataStore