Re: Dragging data to Excel using DoDragDrop



Bruce_Stough wrote:
I am currently using Control.DoDragDrop to drop a text string into Excel. I use the following code

DataObject dd = new DataObject();
dd.SetData(DataFormats.Text,"\\\\ws-it-bstough\\ShareFolder\\Test.wav");
DoDragDrop(dd,DragDropEffects.Copy);

The code works as expected but it will always populate into Excel as a string literal and not as a link to the audio file. If I type the path into a excel the link appears correctly. I am using a windows form in C# to initiate the drag request.

Any Suggestions ?

I'm not sure you're going to be able to do that using the Text data format. I've noticed in the past that Excel won't auto-recognize URLs, UNC paths, etc. except when parsing direct user-input.

If you were using automation, there might be a way to get it to do the recognition explicitly, but AFAIK you can't hook that up to a simple D&D operation.

The one thing that does come to mind is the possibility of creating a ..lnk format object for the DataObject. That might be in a format Excel would recognize and paste in as an actual link.

Of course, how exactly to do that doesn't come immediately to mind. I guess you'll have to look into that yourself. But it's a thought anyway. :)

Pete
.



Relevant Pages