By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,667 Members | 2,255 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,667 IT Pros & Developers. It's quick & easy.

How to determine the drag and drop destination?

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.