# Drag and Drop from Filessytem

**URL:** <https://forum.servoy.com/t/drag-and-drop-from-filessytem/19706>\
**Category:** Classic Servoy\
**Created:** [June 1, 2018, 1:02pm UTC](https://forum.servoy.com/t/drag-and-drop-from-filessytem/19706 "2018-06-01T13:02:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![GabrielWyss](https://avatars.discourse-cdn.com/v4/letter/g/ed8c4c/32.png) [@GabrielWyss](https://forum.servoy.com/u/GabrielWyss)\
**Post date:** [June 1, 2018, 1:02pm UTC](https://forum.servoy.com/t/drag-and-drop-from-filessytem/19706/1 "2018-06-01T13:02:32Z")

</div>

Is it possible to get a filehandle with drag and drop from Windows-Explorer to a Servoy Solution?

Thanks for any help.

---

<div class="post-metadata">

**Author:** ![Ruben79](https://avatars.discourse-cdn.com/v4/letter/r/b782af/32.png) [@Ruben79](https://forum.servoy.com/u/Ruben79)\
**Post date:** [June 1, 2018, 3:38pm UTC](https://forum.servoy.com/t/drag-and-drop-from-filessytem/19706/2 "2018-06-01T15:38:48Z")

</div>

I’m sure it’s possible in smart-client and ngclient. Not sure about webclient.  
For NGclient there is the FileUpload web component: [https://github.com/Servoy/servoy-extra- … Fileupload](https://github.com/Servoy/servoy-extra-components/wiki/Fileupload). Really easy to use.  
For smartclient you can just implement the onDrop event of a form and checkout the event that is passed. We do something like this:

```auto
/**
 * Handle a drag over. Determines of a drop is allowed in this location.
 *
 * Return true is drop is allowed, otherwise false.
 *
 * @param {JSDNDEvent} event the event that triggered the action
 *
 * @returns {Boolean}
 *
 * @protected
 *
 * @properties={typeid:24,uuid:"F30ED7CA-06DA-4137-AE6C-46FB7024C12E"}
 */
function onDragOver(event) {
	var log = scopes.svyLogManager.getLogger('stb.filednd'),
	log.debug('onDragOver triggered');

	if (event.getSource() && event.data) {
		elements.droparea.visible = true;
		return true;
	}
	return false;
}

/**
 * Handle a drop.
 * Return true if drop has been performed successfully, otherwise false.
 *
 * @param {JSDNDEvent} event the event that triggered the action
 *
 * @returns {Boolean}
 *
 * @protected
 *
 * @properties={typeid:24,uuid:"A7CA099B-8F5A-4BE6-91E8-992B887A6E14"}
 */
function onDrop(event) {
	var log = scopes.svyLogManager.getLogger('stb.filednd'),
		result = false,
		content,

		/** @type {plugins.file.JSFile[]} */
		files = [];

	log.debug('onDrop triggered');
	try {
		// check if the dragged stuff is a file
		log.debug('Preparing for a drop');
		if (event && event.dataMimeType && event.dataMimeType.indexOf('application/x-java-file-list') > -1) {
			
			content = event.data.toArray();
			files = content.map(function(f) {
				return plugins.file.convertToJSFile(f);
			})
			
			files.forEach(/** @param {plugins.file.JSFile} file */
			function(file) {
				if (file.isDirectory()) {
					log.debug('Not saving directory {}', file.getAbsolutePath())
				} else if (!file.canRead()) {
					log.debug('Cannot read file {}', file.getAbsolutePath())
				} else if (file.exists()) {
					log.debug('Importing file {}', file.getAbsolutePath())
					// save the file
				}
			});
				
			result = true;	
		
		} else {
			throw 'Dropped stuff was not recognized as a file.';
		}
		log.debug('Drop successful');
	} catch (ex) {
		log.error(ex.toString());
	} finally {
		elements.droparea.visible = false;	
	}

	return result
}

/**
 * Handle end of a drag.
 *
 * @param {JSDNDEvent} event the event that triggered the action
 *
 * @protected
 *
 * @properties={typeid:24,uuid:"F49045DC-B1F1-4A8A-820D-19DF997C1110"}
 */
function onDragEnd(event) {
	elements.droparea.visible = false;	
}

```

---

<div class="post-metadata">

**Author:** ![mboegem](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/mboegem/32/4399_2.png) [@mboegem](https://forum.servoy.com/u/mboegem)\
**Post date:** [June 2, 2018, 11:07am UTC](https://forum.servoy.com/t/drag-and-drop-from-filessytem/19706/3 "2018-06-02T11:07:18Z")

</div>

I’ve done this on web client too, but it’s a lot more work  
I think I used dropzoneJS for that

---

<div class="post-metadata">

**Author:** ![swingman](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/swingman/32/4536_2.png) [@swingman](https://forum.servoy.com/u/swingman)\
**Post date:** [June 5, 2018, 8:17am UTC](https://forum.servoy.com/t/drag-and-drop-from-filessytem/19706/4 "2018-06-05T08:17:57Z")

</div>

Hi Ruben,

the smart-client code, does it work on Java 8? I tried it in developer on the Mac and I could not get it to work.  
Drag-and-drop is another good reason to move to NG-client…
