473,563 Members | 2,703 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to determine the drag and drop destination?

Thi
Hi,

I am trying to develop an application that allows the users to drag a few
file(s) from a zip archive to a destination.

My question is, how do i determine where the drop destination is because i
need to do some validation checking before extracting the files from the zip
archive (e.g. validate archive password).

Any help or some sample codes would be very much appreciated.

Thanks

Thi
www.elmbrook.co.nz
www.backpackpro.co.nz
Jun 17 '07 #1
1 4795
You can't know the destination because that's internal to the drop target.
All it does is ask you for the file list. Best you can hope for is delaying
generation of the physical files until the drop occurs (rather than when the
drag occurs).

The DataObject class (the default implementer of IDataObject) doesn't
support delay-rendering like that, you must create the physical files before
the call to DoDragDrop if you use the DataObject (or use a string array with
DataFormats.Fil eDrop).

If you want to delay extraction until when the drop occurs you can create a
class that implements IDropTarget, implement GetFormats to return at list of
formats containing at least DataFormats.Fil eDrop, implement GetDataPresent to
return true for each format type you support (again, at least
DataFormats.Fil eDrop), then implement GetData that is called when the drop
occurs to extract the files. Following is an example implementation of
DataObject that only supports file drops and generates a C:\test.txt when the
drop occurs (i.e. you can drag without dropping and the file will never get
created):

class MyDataObject : IDataObject {
#region IDataObject Members

public object GetData ( Type format ) {
throw new NotImplementedE xception();
}

public object GetData ( string format ) {
throw new NotImplementedE xception();
}

public object GetData ( string format, bool autoConvert ) {
if (format == DataFormats.Fil eDrop) {
string filePath = @"c:\test.text" ;
File.WriteAllTe xt(filePath, String.Format(" File created {0}\nThis is
some text.\nThis is the end of the file.", DateTime.Now.To String()));
return new string[] { filePath };
}
return null;
}

public bool GetDataPresent ( Type format ) {
throw new NotImplementedE xception();
}

public bool GetDataPresent ( string format ) {
throw new NotImplementedE xception();
}

public bool GetDataPresent ( string format, bool autoConvert ) {
return (format == DataFormats.Fil eDrop);
}

public string[] GetFormats ( ) {
throw new NotImplementedE xception();
}

public string[] GetFormats ( bool autoConvert ) {
return new string[] { DataFormats.Fil eDrop };
}

public void SetData ( object data ) {
throw new NotImplementedE xception();
}

public void SetData ( Type format, object data ) {
throw new NotImplementedE xception();
}

public void SetData ( string format, object data ) {
throw new NotImplementedE xception();
}

public void SetData ( string format, bool autoConvert, object data ) {
throw new NotImplementedE xception();
}

#endregion
}

and can be used as follows:
DoDragDrop(new MyDataObject(), DragDropEffects .Copy);

You'll, of course, want to make it more useful than that... You'll run into
usage issues because you don't know what application is accepting the drop
and therefore can only present a form in your application (which is likely
behind the drop target).

--
Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#
"Thi" wrote:
Hi,

I am trying to develop an application that allows the users to drag a few
file(s) from a zip archive to a destination.

My question is, how do i determine where the drop destination is because i
need to do some validation checking before extracting the files from the zip
archive (e.g. validate archive password).

Any help or some sample codes would be very much appreciated.
Jun 18 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1230
by: nicomp | last post by:
I studied the Drag and Drop example that all the .Net dev sites link to: a string is dragged from one list box to another. It all makes sense but it doesn't explain how to determine what the object being dragged is. The code assumes the object is a string and only verifies that is really is a string. How can I drop into a Select Case and...
3
1905
by: Web Webon | last post by:
Hi everybody! I wonder if this is possible? I need to determine if a client is using "windows classic folders" or anything else. If I instantiate a Shell ActiveX object is there a way of obtaining this information from javascript? (I know that the user will get prompted about allowing such an operation, but I am willing to live with...
0
2410
by: Norbert Heidbüchel | last post by:
Hi all, I have read a lot of postings and web pages about drag and drop and treeviews, but could not find an answer to my problem. Sorry, if I missed something. I am trying to drag and drop treenodes defined by myself and don't understand, how to get the nodes data in the dragdrop event. I'm not very experienced in .NET and for sure there...
0
917
by: Tiraman :-\) | last post by:
Hi, i have a treeview control which handle the drag and drop operations. but when the user trying to drag a node to one of his Childs the all node is gone. so i cover this by doing If InStr(DestinationNode.FullPath, NewNode.Text) = 0 Then
1
4077
by: dotnetnari | last post by:
hi, How to Drag and drop the nodes from treeview into datatable columns using windowsapplication in c# Thanks
1
300
by: Thi | last post by:
Hi, <<<< Sorry for a repost because i really really need help with this one. >>> I am trying to develop an application that allows the users to drag a few file(s) from a zip archive to a destination. My question is, how do i determine where the drop destination is because i need to do some validation checking before extracting the...
6
6458
by: Alfonso2968 | last post by:
Hello, If someone can help plz. I have searched everything and all I can find is how to drag and drop within a form from panel to panel. What I need to do is Drag an image from the desktop or from an open folder to a panel on my form. This will be done for a few images and then on Buttonclik I need to save each image in its own folder.
2
1917
by: Louis | last post by:
I have a problem in doing a drag-and-drop using javascript in Firefox. I can perform the operation when I can see the source and destination. However if the destination is beyond the browser window, and when I drag the mouse to the bottom of the browser window, the window will not scroll. (I know when I reach the top as my y-coordinate will be...
5
13747
by: Romulo NF | last post by:
Greetings, I´m back here to show the new version of the drag & drop table columns (original script ). I´ve found some issues with the old script, specially when trying to use 2 tables with drag&drop on the same page (which was not possible). Now i´ve a new concept of the script, more object oriented. I´ve also commented the whole code so you...
0
7659
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7580
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7882
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7634
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7945
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5208
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3618
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2079
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
916
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.