Drop to Explorer - How to figure out the target directory?

  • Thread starter Thread starter Timothy Lee Russell
  • Start date Start date
T

Timothy Lee Russell

When you drag out of a Winforms app and drop it onto explorer, is there a
way -- perhaps using IDataObject -- to figure out what directory was dropped
to?



I want to handle all the file i/o from my app, rather than populating a
DataObject...



Basically, dropping the actual files themselves is problematic, since they
don't exist at the time that the drag/drop operation takes place. At that
point, they are just filenames that exist out on the interweb.



I've got a semi-working delayed write mechanism by implementing IDataObject
but it is overly complicated and not ideal -- when all I really need to know
is the target directory.



Thanks,

Timothy
 
Timothy Lee Russell said:
Basically, dropping the actual files themselves is problematic, since they
don't exist at the time that the drag/drop operation takes place. At that
point, they are just filenames that exist out on the interweb.



I've got a semi-working delayed write mechanism by implementing
IDataObject but it is overly complicated and not ideal -- when all I
really need to know is the target directory.

There is no easy solution to this problem. I had the same problem in my app.
You can't create the file when drag starts because it might take too long
and the drop might never happen. You need to create the file or data stream
when it is dropped. This is possible but very difficult and requires all
sorts of com interop. I don't have a solution but I might be able to send
you my partial solution if you promise to send me back the results if you
complete it.

Michael
 
I want to handle all the file i/o from my app, rather than populating a
DataObject...

File extraction tools such as WinZip and WinRar have the same problem,
and they seem to solve it by first extracting the files to a temp
directory.

You have to keep in mind that there might not be a target directory at
all. The target can be any virtual directory in the shell namespace,
so doing conventional file IO to create a file directly there might
not work.


Mattias
 
Mattias Sjögren said:
File extraction tools such as WinZip and WinRar have the same problem,
and they seem to solve it by first extracting the files to a temp
directory.

I'm not sure whether they do that or not but they certainly don't need to.
It's quite possible to stream data out of your app to explorer and explorer
will create the file.
You have to keep in mind that there might not be a target directory at
all. The target can be any virtual directory in the shell namespace,
so doing conventional file IO to create a file directly there might
not work.

Presumably streaming will solve the problem.

Michael
 
Michael,

Thanks for the answer. The files would definitely take too long to create
on drag -- and especially if it were multiple files because it would first
have to download them over the internet. (You'd have to hold the left mouse
button for a couple of days -- no big deal)...

Another problem is that if you provide the file download in the GetData
method, it is not multi-threaded which is a requirement of my program.

Of course, this can all be "solved" by right-clicking on the selected files
and having a directory chooser dialog but I want my program to be a first
class windows citizen!

What I really wish is that I could just interrogate the callback from the
drop to figure out where I just dropped.

I would be most interested in any examples that you have that would
demonstrate how you are trying to solve the problem and I would be glad to
pass back anything I figure out.

Thanks,
Timothy
 
Mattias,

Unfortunately, I can't create a temp directory with the files in it any
faster than I can directly provide the data using the GetData method --
since the files that I am referencing are being stored out in the "cloud".

One filename that I drag to explorer might reference a 1.5 GB file, while
another might be a directory that contains 1/2 million 50k files. Really
though, all I have at the time of the drag is a bunch of filenames.

It's like showing up to a date with a gift card for flowers but not the
actual flowers themselves.

I am going to do some research into the shell namespace.

Thanks,
Timothy
 
Timothy Lee Russell said:
Michael,

Thanks for the answer. The files would definitely take too long to create
on drag -- and especially if it were multiple files because it would first
have to download them over the internet. (You'd have to hold the left
mouse button for a couple of days -- no big deal)...

Another problem is that if you provide the file download in the GetData
method, it is not multi-threaded which is a requirement of my program.

Of course, this can all be "solved" by right-clicking on the selected
files and having a directory chooser dialog but I want my program to be a
first class windows citizen!

What I really wish is that I could just interrogate the callback from the
drop to figure out where I just dropped.

I would be most interested in any examples that you have that would
demonstrate how you are trying to solve the problem and I would be glad to
pass back anything I figure out.

Give me a day or 2, I'm having trouble finding it but wouldn't have deleted
it. I believe I was on to the "correct" way to do it, I just couldn't get it
to work.

Michael
 
Timothy Lee Russell said:
I would be most interested in any examples that you have that would
demonstrate how you are trying to solve the problem and I would be glad to
pass back anything I figure out.

I still haven't forgotten about this if you're still interested. I'm having
a look for it now.

Michael
 
Back
Top