Drag and Drop attachment from Outlook to RadGridView

14 posts, 0 answers
  1. Chris
    Chris avatar
    9 posts
    Member since:
    Feb 2011

    Posted 20 Sep 2012 Link to this post

    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
  2. Nick
    Admin
    Nick avatar
    593 posts

    Posted 24 Sep 2012 Link to this post

    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.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Chris
    Chris avatar
    9 posts
    Member since:
    Feb 2011

    Posted 24 Sep 2012 Link to this post

    Hi,

        Thanks for the reply.

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

    Thanks,
    Chris
  5. Nick
    Admin
    Nick avatar
    593 posts

    Posted 24 Sep 2012 Link to this post

    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.

  6. Valerie
    Valerie avatar
    36 posts
    Member since:
    Nov 2011

    Posted 07 May 2013 Link to this post

    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: 



  7. Nick
    Admin
    Nick avatar
    593 posts

    Posted 08 May 2013 Link to this post

    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.

  8. Valerie
    Valerie avatar
    36 posts
    Member since:
    Nov 2011

    Posted 10 May 2013 Link to this post

    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
  9. Yoan
    Admin
    Yoan avatar
    1066 posts

    Posted 15 May 2013 Link to this post

    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.


  10. Valerie
    Valerie avatar
    36 posts
    Member since:
    Nov 2011

    Posted 15 May 2013 Link to this post

    Are you referring to what I posted here 5 days ago or something else?
  11. Sashi
    Sashi avatar
    5 posts
    Member since:
    Mar 2013

    Posted 29 Jul 2014 in reply to Nick Link to this post

    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
  12. Nick
    Admin
    Nick avatar
    593 posts

    Posted 30 Jul 2014 Link to this post

    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.
     
  13. Sashi
    Sashi avatar
    5 posts
    Member since:
    Mar 2013

    Posted 08 Aug 2014 in reply to Nick Link to this post

    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.
  14. Sashi
    Sashi avatar
    5 posts
    Member since:
    Mar 2013

    Posted 12 Aug 2014 in reply to Sashi Link to this post

    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);
     
            }
          }
        }
        
      }
    }
  15. Pat
    Pat avatar
    7 posts
    Member since:
    Jan 2015

    Posted 08 Mar in reply to Sashi Link to this post

    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.
Back to Top
UI for WPF is Visual Studio 2017 Ready