This is a migrated thread and some comments may be shown as answers.

Drag and Drop attachment from Outlook to RadGridView

13 Answers 133 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 20 Sep 2012, 03:25 PM
Hi,

    I was able to implement the drag and drop from Windows Explorer using the RadDragAndDropManager with native mode, which works well.

     However, is it possible to drag and drop an attachment from Outlook to RadGridView? How?

Thanks,
Chris

13 Answers, 1 is accepted

Sort by
0
Nick
Telerik team
answered on 24 Sep 2012, 01:07 PM
Hi Chris,

Unfortunately this is a limitation of the RadDragAndDropManager. 
You can use the DragDropManager. To achieve the desired behavior you can get the Data in the Drop event, and extract the necessary information from the DataObject.

Let me know if you need any further help with this. 

Greetings,
Nik
the Telerik team

Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

0
Chris
Top achievements
Rank 1
answered on 24 Sep 2012, 01:27 PM
Hi,

    Thanks for the reply.

    Do you have a sample code or project on how to do it?

Thanks,
Chris
0
Nick
Telerik team
answered on 24 Sep 2012, 01:50 PM
Hi Chris,

You can use the DragDroppayloadManager class to see what are the available formats in the CurrentPayload, and extract them later on. Here is a simple example. 

private void OnDrop(object sender, Telerik.Windows.DragDrop.DragEventArgs e)
{
    if (DragDropPayloadManager.GetFormats(e.Data).Contains("FileContents"))
    {
        try
        {
            var stream = DragDropPayloadManager.GetDataFromObject(e.Data, "FileContents");
 
        }
        catch
        {
        }
    }
}

Hope this helps!  All the best,
Nik
the Telerik team

Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

0
Valerie
Top achievements
Rank 1
answered on 07 May 2013, 07:05 PM
Hi,
I am using the DragDropManager and when I add the code below to my project, the line
var stream = DragDropPayloadManager.GetDataFromObject(e.Data, "FileContents");

in the OnDrop callback throws an exception every time. Here is what I get. Do you know what could be causing this?
Thanks, Valerie

System.Runtime.InteropServices.COMException was caught
  Message=Invalid lindex (Exception from HRESULT: 0x80040068 (DV_E_LINDEX))
  Source=System
  ErrorCode=-2147221400
  StackTrace:
       at System.Runtime.InteropServices.ComTypes.IDataObject.GetData(FORMATETC& format, STGMEDIUM& medium)
       at System.Windows.DataObject.OleConverter.GetDataInner(FORMATETC& formatetc, STGMEDIUM& medium)
       at System.Windows.DataObject.OleConverter.GetDataFromOleIStream(String format, DVASPECT aspect, Int32 index)
       at System.Windows.DataObject.OleConverter.GetDataFromBoundOleDataObject(String format, DVASPECT aspect, Int32 index)
       at System.Windows.DataObject.OleConverter.GetData(String format, Boolean autoConvert, DVASPECT aspect, Int32 index)
       at System.Windows.DataObject.OleConverter.GetData(String format, Boolean autoConvert)
       at System.Windows.DataObject.GetData(String format, Boolean autoConvert)
       at System.Windows.DataObject.GetData(String format)
       at Telerik.Windows.DragDrop.DragDropPayloadManager.GetDataFromObject(Object draggedObject, String format) in c:\TB\221\WPF_Scrum\Release_WPF\Sources\Development\Core\Controls\DragDropManager\DragDropPayloadManager.cs:line 52
       at Desktop.Infrastructure.RadTreeViewDragDropBehavior.OnDrop(Object sender, DragEventArgs e) in C:\WCLX\Code Review Workspace\Desktop\Desktop\Infrastructure\RadTreeViewDragDropBehavior.cs:line 264
  InnerException: 



0
Nick
Telerik team
answered on 08 May 2013, 07:55 AM
Hello Valerie,

Unfortunately I cannot say anything with certainty about this. What is your scenario? Is your application running in elevated trust? Do you modify the DataObject in any way prior to extracting the data from it?

All the best,
Nik
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Valerie
Top achievements
Rank 1
answered on 10 May 2013, 02:57 PM
I am not running in elevated trust mode. The best I can do is give you a demo project showing the problem. I can't attach that here so I will have to open a ticket.
Thanks, Valerie
0
Yoan
Telerik team
answered on 15 May 2013, 02:03 PM
Hi Valerie,

I have already answered to your support ticket. In order to make our communication consistent, it would be better to follow a single thread on the topic.

Kind regards,
Yoan
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.


0
Valerie
Top achievements
Rank 1
answered on 15 May 2013, 05:02 PM
Are you referring to what I posted here 5 days ago or something else?
0
Sashi
Top achievements
Rank 1
answered on 29 Jul 2014, 02:43 PM
Hey Nik...could you please point me to an example on how to drag and drop an attachment from Outlook to RadGridView using the DragDropManager?..


Thanks,
-Sashi
0
Nick
Telerik team
answered on 30 Jul 2014, 11:56 AM
Hi Sashi,

Basically the only thing special about the case is that you have to look for specific data format in the comming DataObject(args.Data). Everything else behaves in the same way as a default DragDrop scenario, the only thing special is to extract the data form the DataObject, which can be done by using the DragDropPayloadManager class with the GetDataFromObject method. 

Let me know if I can help you further with this. 

Regards,
Nik
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Sashi
Top achievements
Rank 1
answered on 08 Aug 2014, 11:02 PM
Hi Nik, thanks for getting back to me..I was able to get the DragDropManager working finally...if I was dragging and dropping a bunch of files from the file explorer...my loop would look something like this...‚Äč

var data = e.Data as DataObject;
if (data != null && data.ContainsFileDropList())
{
var files = data.GetFileDropList();
foreach (var file in files)
{
Do FileInfo, get information about the file and Get the bytes...
}
}

along the same lines...If I was to drag and drop an outlook message which has a bunch of attachments..how would my loop look like..i see keys like "FileContents" , "FileGroupDesc..W" etc...wondering how to put a loop together similar to the windows explorer scenario..

Thanks,
-Sashi.
0
Sashi
Top achievements
Rank 1
answered on 12 Aug 2014, 07:50 PM
Here is how..just in case someone else runs into the same scenario..

if (e.Data.GetFormats().Contains("FileGroupDescriptorW"))
{
  using (Stream o2 = (Stream)e.Data.GetData("FileGroupDescriptorW"))
  {
    string SchemaPR_ATTACH_CONTENT_ID = @"http://schemas.microsoft.com/mapi/proptag/0x3712001E";
    string SchemaPR_ATTACH_CONTENT_LOCATION = @"http://schemas.microsoft.com/mapi/proptag/0x3713001E";
    string SchemaPR_ATTACH_METHOD = @"http://schemas.microsoft.com/mapi/proptag/0x37050003";
    string SchemaPR_ATTACH_FLAGS = @"http://schemas.microsoft.com/mapi/proptag/0x37140003";

    Microsoft.Office.Interop.Outlook.Application outlook = new Microsoft.Office.Interop.Outlook.Application();
    Microsoft.Office.Interop.Outlook.Selection sel = outlook.ActiveExplorer().Selection;

    foreach (object item in sel)
    {
      if (item is Microsoft.Office.Interop.Outlook.MailItem)
      {
        Microsoft.Office.Interop.Outlook.MailItem mail = item as Microsoft.Office.Interop.Outlook.MailItem;
        foreach (Microsoft.Office.Interop.Outlook.Attachment attachment in mail.Attachments)
        {
          dynamic AttachCID = attachment.PropertyAccessor.GetProperty(SchemaPR_ATTACH_CONTENT_ID);
          dynamic AttachContentLocation = attachment.PropertyAccessor.GetProperty(SchemaPR_ATTACH_CONTENT_LOCATION);
          dynamic AttachFlags = attachment.PropertyAccessor.GetProperty(SchemaPR_ATTACH_FLAGS);
          dynamic AttachMethod = attachment.PropertyAccessor.GetProperty(SchemaPR_ATTACH_METHOD);

          /*
                          * If ATTACH_CONTENT_ID or ATTACH_CONTENT_LOCATION are present and are not null
                          * string the attachment is embedded. Those are string (PT_STRING8) properties.
                          * If ATTACH_METHOD, a long (PT_LONG) property is there and has a value of 6
                          * it's embedded. If ATTACH_FLAGS, a long (PT_LONG) is there and has a value
                          * of 4 it's embedded.
                          */
          bool IsEmbededAttachment = !String.IsNullOrEmpty(AttachCID) || !String.IsNullOrEmpty(AttachContentLocation)
            || AttachFlags == 4 || AttachMethod == 6;

          if (IsEmbededAttachment) continue;
 
            string abosolutePath = System.IO.Path.Combine(SomeDir, attachment.FileName);
            attachment.SaveAsFile(abosolutePath);
 
        }
      }
    }
    
  }
}
0
Pat
Top achievements
Rank 1
answered on 08 Mar 2016, 05:10 PM
Sashi's post is interesting.    But it doesn't actually handle the dropped item.   Instead it opens outlook, finds the selected item and processes that.    Sometimes that might be the same thing but not always.
Tags
DragAndDrop
Asked by
Chris
Top achievements
Rank 1
Answers by
Nick
Telerik team
Chris
Top achievements
Rank 1
Valerie
Top achievements
Rank 1
Yoan
Telerik team
Sashi
Top achievements
Rank 1
Pat
Top achievements
Rank 1
Share this question
or