Drag and drop files


Purpose
This sample demonstrates how to drop layer files (.lyr) or map documents (.mxd) dragged from ArcCatalog and Windows Explorer onto the Map control. To drop data onto the Map control, the OleDropEnabled property is set to true, which allows the OnOleDrop event to trigger when data is dragged over the control.
 
When dragged data initially enters the Map control, the OnOleDrop event is triggered with an esriDropEnter action. The IDataObjectHelper interface is used to determine whether the data is being dragged from ArcCatalog or Windows Explorer using the CanGetNames and CanGetFiles methods. If the data is from ArcCatalog or Windows Explorer, DragDropEffect is set to esriDragDropCopy; otherwise, it's set to esriDragDropNone. DragDropEffect is then stored for later use.
 
When data is dragged around the Map control, the OnOleDrop event is triggered with an esriDropOver action. DragDropEffect is set to the effect stored when the data initially entered the control, and the mouse coordinates are updated on the form. The MapControl OnMouseMove event updates the coordinates on the form when the OnOleDrop event is not being triggered.
 
When data is dropped onto the Map control, the OnOleDrop event is triggered with an esriDropped action. The IDataObjectHelper interface is used to obtain an array of file path strings from the data using the GetFiles method if the CanGetFiles method returns true; otherwise, an IEnumName collection is obtained using the GetNames method.
 
The CheckMxFile method is used to determine whether each file path in the array is a valid Mx document. If valid, the LoadMxFile method is used to load the document onto the Map control; otherwise, an IFileName object is created with its path property set to the file path in the array. The IFileName object is used to create a layer that can be added to the Map control (in the same way that the IName objects obtained by enumerating the IEnumName collection are). Mx document and layer files, if dropped from ArcCatalog, return true for CanGetFiles because they are both a type of IFileName.
 
The ILayerFactoryHelper interface is used to create a collection of ILayer objects using the CreateLayersFromName method. Each layer is added to the Map control using the AddLayer method.

How to use

See How to use ArcGIS samples for help on running the sample. If the sample has associated data, you will find that the sample's zip file includes a "data" folder alongside the language folders. However, you will need to update the sample to point to the location of the data once you have extracted all the files.

  1. Run the DragAndDropFiles application.
  2. Confirm that the Enable File Dropping check box is checked.
  3. Drag and drop layer files or map documents from ArcCatalog and Windows Explorer onto the Map control.


Download the files for Java
mapbean/DragAndDropFiles.java Main class




Development licensing Deployment licensing
Engine Developer Kit Engine Runtime
ArcView
ArcEditor
ArcInfo