none
VSTO Addin > Facing problem in implementing Drag-Drop functionality > Need help! RRS feed

  • Question

  • Hello,

    I have implemented DragNDrop functionality in my VSTO Addin but am facing 2 problems - 

    1. MS Word - Images are not getting dropped. But I can see a place holder for it in the document. When I right click it & select "Edit Image" & then just close the message box, it starts showing the image.
    2. MS Outlook - The complete content is not getting Dropped.

    Please note that my source data is in HTML format. While calling the DoDragDrop, the data object I am passing is set for the HTML format.

    Please feel free to let me know in case I have missed any information to be passed.

    Can someone please guide what needs to be done to fix the above issues?

    Thanks!



    -Vinay Pugalia
    If a post answers your question, please click "Mark As Answer" on that post or "Vote as Helpful".
    Web : Inkey Solutions
    Blog : My Blog
    Email : Vinay Pugalia

    Friday, April 15, 2016 10:25 AM

Answers

  • Hello Edward,

    I have got this working perfectly as expected.

    I have followed the below steps - 

    1. Took a WebBrowser control
    2. Set it's DocumentText property with the HTML string I have
    3. I then selected all the content of the WebBrowser control & copied it to the clipboard as under - 
      wb.Document.ExecCommand("SelectAll", false, null); wb.Document.ExecCommand("Copy", false, null);
    4. Next I do the following - 
    DataObject dataObject = new DataObject();					
       dataObject.SetData(Clipboard.GetDataObject());
       IconButton.DoDragDrop(dataObject,DragDropEffects.Copy);									

    And this works perfectly as expected.

    Could you please guide if this has any side effects?

    Thanks!


    -Vinay Pugalia
    If a post answers your question, please click "Mark As Answer" on that post or "Vote as Helpful".
    Web : Inkey Solutions
    Blog : My Blog
    Email : Vinay Pugalia

    Friday, May 13, 2016 2:59 PM

All replies

  • Hi Vinay,

    >> I have implemented DragNDrop functionality in my VSTO Addin but am facing 2 problems

    Do you develop Word VSTO add in or Outlook VSTO add in? How did you implement Drag-Drop? In my option, there is no built-in drag and drop function in Outlook Object Model. It would be helpful if you could share us a simple code to reproduce your issue.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, April 18, 2016 2:13 AM
  • Hello Edward,

    My VSTO Addin is basically added in a custom panel. Hence, works for all - Word/Excel/PPT & Outlook.

    I have created a separate project having my UserControl & then have added the same in all the office addin projects.

    Below is the code snippet I have written for Drag-Drop - 

    DataObject dataObject = new DataObject();
    //Currently we are fetching text.
    string strContent = "Some HTML Text";
    dataObject.SetData(DataFormats.HTML, strContent);                    
    button.DoDragDrop(dataObject, DragDropEffects.Copy);

    The above code works well in Word except the image(s) are not shown (images are in img tag of html) & for outlook nothing happens until we change the DatFormat to TEXT from HTML.

    I have not tested it for excel & ppt.

    Please guide.


    -Vinay Pugalia
    If a post answers your question, please click "Mark As Answer" on that post or "Vote as Helpful".
    Web : Inkey Solutions
    Blog : My Blog
    Email : Vinay Pugalia

    Monday, April 18, 2016 5:17 AM
  • Hi Vinay,

    >> My VSTO Addin is basically added in a custom panel

    Do you mean you develop with office custom task pane?

    Based on your code, it seems you are using Metodo Control.DoDragDrop (Object, DragDropEffects). How did you use this code in Word add in? Could you share us a complete simple code? Where did you drag and drop? Did you mean you drag from your UserControl and drop to word? How did you write the content to word?

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Tuesday, April 19, 2016 3:05 AM
  • Hello Edward,

    Yes, I want to drag from my control in the custom task pane & drop the content in word/outlook/excel/power point.

    And my code looks more or less the same as the example in this link. I mean there is nothing extra ordinary in the code. Still, could you please let me know what exactly you want me to share? (Actually, the current state of code has got a little messy - as I am trying a lot of things in it to get the work done).

    And yes, the drop of the content is handled by Word/Outlook itself. I have not written anything extra for it.


    -Vinay Pugalia
    If a post answers your question, please click "Mark As Answer" on that post or "Vote as Helpful".
    Web : Inkey Solutions
    Blog : My Blog
    Email : Vinay Pugalia

    Tuesday, April 19, 2016 4:23 AM
  • Hi Vinay,

    >> 1.MS Word - Images are not getting dropped. But I can see a place holder for it in the document. When I right click it & select "Edit Image" & then just close the message box, it starts showing the image.

    I am unclear about how you achieved this, so I ask for a simple demo to reproduce your issue.

    >> drop of the content is handled by Word/Outlook itself. I have not written anything extra for it.

    Achieving drag and drop content from task pane to word can be complex, because word has its own way to identify the drag-and-drop operation, and it inserts the dropped object as-is. It seems you will need to custom drop operation to achieve drag-drop image correctly. You could insert a image in word in DragDrop event in winform control.

    You could refer the link below for more information.

    # Using the Drag-and-Drop Operation with VSTO Add-ins in Word 2010

    https://msdn.microsoft.com/en-us/library/office/hh780901(v=office.14).aspx

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Tuesday, April 19, 2016 7:40 AM
  • Hello Edward,

    As said, the code is nothing extra ordinary. The below is the only code I have written to get the drag drop working - 

    if (MouseButtons == MouseButtons.Left && IconButton != null)
    {
       DataObject dataObject = new DataObject();					
       dataObject.SetData(DataFormats.Html, true, Content);
       IconButton.DoDragDrop(dataObject,DragDropEffects.Copy);									
    }

    In the above code, "Content" variable has got the HTML string in it and the HTML has got the styling too - <B> or <br> etc. along with the <img src...> tags.

    Also, please note that the code is written on the mouse_down event handler of the IconButton.

    Now what happens is, word has started showing the content in plain text..I am not sure what has been changed. As, when I implemented it initially, at least I was able to get the rich text in the word document after dropping.

    Seems, either I am missing something very simple or am far from getting it done the right way.

    Can you please share your views on this?


    -Vinay Pugalia
    If a post answers your question, please click "Mark As Answer" on that post or "Vote as Helpful".
    Web : Inkey Solutions
    Blog : My Blog
    Email : Vinay Pugalia


    Tuesday, April 19, 2016 8:41 AM
  • Hi Vinay,

    As my above reply, if you want to drag and drop content from task pane to word, you will need to achieve present details in word, you could refer my above link for details steps.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, April 20, 2016 2:30 AM
  • Hello Edward,

    I will again take a deep look at the link you have shared on # Using the Drag-and-Drop Operation with VSTO Add-ins in Word 2010 and try to fix the issues in the implementation.

    Will revert once done.

    Thanks!


    -Vinay Pugalia
    If a post answers your question, please click "Mark As Answer" on that post or "Vote as Helpful".
    Web : Inkey Solutions
    Blog : My Blog
    Email : Vinay Pugalia

    Wednesday, April 20, 2016 4:30 AM
  • Hi Viany,

    If you have any updates, please feel free to let us know.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Thursday, April 21, 2016 2:31 AM
  • Hello Edward,

    I have got this working perfectly as expected.

    I have followed the below steps - 

    1. Took a WebBrowser control
    2. Set it's DocumentText property with the HTML string I have
    3. I then selected all the content of the WebBrowser control & copied it to the clipboard as under - 
      wb.Document.ExecCommand("SelectAll", false, null); wb.Document.ExecCommand("Copy", false, null);
    4. Next I do the following - 
    DataObject dataObject = new DataObject();					
       dataObject.SetData(Clipboard.GetDataObject());
       IconButton.DoDragDrop(dataObject,DragDropEffects.Copy);									

    And this works perfectly as expected.

    Could you please guide if this has any side effects?

    Thanks!


    -Vinay Pugalia
    If a post answers your question, please click "Mark As Answer" on that post or "Vote as Helpful".
    Web : Inkey Solutions
    Blog : My Blog
    Email : Vinay Pugalia

    Friday, May 13, 2016 2:59 PM
  • Hi Vinay,

    Thanks for sharing, and i suggest you mark your reply as answer, and then others who run into the same issue would find the solution easily.

    At moment, I have no suggestion about this, and if you have any issues about this way, i suggest you post your issue in this forum again.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, May 16, 2016 2:00 AM