# Drag a file from Windows and drop it in a client

**URL:** <https://forum.inductiveautomation.com/t/drag-a-file-from-windows-and-drop-it-in-a-client/12680>\
**Category:** Ignition\
**Created:** [February 14, 2017, 9:52pm UTC](https://forum.inductiveautomation.com/t/drag-a-file-from-windows-and-drop-it-in-a-client/12680 "2017-02-14T21:52:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![DougSN](https://avatars.discourse-cdn.com/v4/letter/d/a9adbd/32.png) [@DougSN](https://forum.inductiveautomation.com/u/DougSN)\
**Post date:** [February 14, 2017, 9:52pm UTC](https://forum.inductiveautomation.com/t/drag-a-file-from-windows-and-drop-it-in-a-client/12680/1 "2017-02-14T21:52:11Z")

</div>

I would like to have a component on my screen that allows a user to drag a file from Windows into it, and then it will record the filepath. I haven’t found a component that allows for file dropping, so I’m unsure how to proceed. If it matters, in this case the files would always be a PDF, but I could see this being used for other things later.

If there is not a component that has this function built in, hack jobs are accepted 🙂

---

<div class="post-metadata">

**Author:** ![adam.morales](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/adam.morales/32/3405_2.png) [@adam.morales](https://forum.inductiveautomation.com/u/adam.morales)\
**Post date:** [February 14, 2017, 10:11pm UTC](https://forum.inductiveautomation.com/t/drag-a-file-from-windows-and-drop-it-in-a-client/12680/2 "2017-02-14T22:11:32Z")

</div>

We have a component called the ‘File Explorer’ which can list files in a given root directory and has a property showing the path that the operator has selected. This may not be exactly what you are looking for, but perhaps worth looking into using.

---

<div class="post-metadata">

**Author:** ![DougSN](https://avatars.discourse-cdn.com/v4/letter/d/a9adbd/32.png) [@DougSN](https://forum.inductiveautomation.com/u/DougSN)\
**Post date:** [February 14, 2017, 10:12pm UTC](https://forum.inductiveautomation.com/t/drag-a-file-from-windows-and-drop-it-in-a-client/12680/3 "2017-02-14T22:12:51Z")

</div>

Definitely worth a look, thank you for the suggestion.

---

<div class="post-metadata">

**Author:** ![jpark](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@jpark](https://forum.inductiveautomation.com/u/jpark)\
**Post date:** [February 14, 2017, 10:40pm UTC](https://forum.inductiveautomation.com/t/drag-a-file-from-windows-and-drop-it-in-a-client/12680/4 "2017-02-14T22:40:04Z")

</div>

Put a container or label on the screen. You will be dragging a file / files onto this component.  
Put a button on the screen with the following code.

[code]from java.awt.dnd import DropTargetListener,DnDConstants,DropTarget

class MyDragDropListener(DropTargetListener):  
def drop(self,e):  
e.acceptDrop(DnDConstants.ACTION\_COPY)  
transferable = e.getTransferable()  
flavors = transferable.getTransferDataFlavors()  
for flavor in flavors:  
if (flavor.isFlavorJavaFileListType()):  
files = transferable.getTransferData(flavor)  
for f in files:  
print "File path is: ", f.getPath()  
e.dropComplete(True)

comp = event.source.parent.getComponent(‘Container’)

myDragDropListener = MyDragDropListener()

DropTarget(comp, myDragDropListener)[/code]

---

<div class="post-metadata">

**Author:** ![DougSN](https://avatars.discourse-cdn.com/v4/letter/d/a9adbd/32.png) [@DougSN](https://forum.inductiveautomation.com/u/DougSN)\
**Post date:** [February 14, 2017, 10:58pm UTC](https://forum.inductiveautomation.com/t/drag-a-file-from-windows-and-drop-it-in-a-client/12680/5 "2017-02-14T22:58:23Z")

</div>

Thanks! This is the kind of thing I was hoping to get. Looks like it is working and I can modify it for my application.
