473,387 Members | 1,585 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 4772
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.FileDrop).

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.FileDrop, implement GetDataPresent to
return true for each format type you support (again, at least
DataFormats.FileDrop), 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 NotImplementedException();
}

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

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

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

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

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

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

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

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

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

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

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

#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
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...
3
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...
0
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...
0
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...
1
by: dotnetnari | last post by:
hi, How to Drag and drop the nodes from treeview into datatable columns using windowsapplication in c# Thanks
1
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...
6
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...
2
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...
5
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.