Link to home
Create AccountLog in
Avatar of thready
thready

asked on

Get filename of dragged icon on Windows

Hi Experts,

Is there a way to subscribe to file drag events in Windows, in order to obtain the full path to the file that was dragged?   i.e., before the file is dropped?

Thanks,
Mike
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
is that C++ or C# that you need? Winforms or WPF?
Avatar of thready
thready

ASKER

C#   :-)
Thanks jkr! ! !
Avatar of thready

ASKER

I'll try this tomorrow morning!
Winforms or WPF?
Avatar of thready

ASKER

Wpf...
No need to use Shell. Here is a WPF sample:

public MainWindow()
{
	InitializeComponent();
	TextBox1.AllowDrop = true;
	TextBox1.PreviewDragEnter += TextBox1_DragEnter;
}

private void TextBox1_DragEnter(object sender, DragEventArgs e)
{
	Label1.Content = string.Empty;

	if (e.Data.GetDataPresent(DataFormats.FileDrop, true))
	{
		string[] filenames = (string[])e.Data.GetData(DataFormats.FileDrop, true);
		foreach (string filename in filenames)
		{
			Label1.Content += filename + "  ";
		}
	}
	e.Effects = DragDropEffects.All;
	e.Handled = true;
}

Open in new window

Avatar of thready

ASKER

I don't want to detect drops, I want to detect the start of drag only.
My code lets you preview before you drop. The drop is not handled. What are your trying to do exactly?
Avatar of thready

ASKER

Ok, I read it too quick.  Thanks a lot for your help.  I'd love to be able to tell you but I should not because of work...  Sorry.  I'll try tomorrow morning.  Thanks again!
Avatar of thready

ASKER

I don't think your method will work Eric, I don't have a textbox to preview..  I really only want Windows messages with no ui involved from my app...
Avatar of thready

ASKER

jkr, I don't think I can get the shell method to work either.  My program is minimized and the drop target is not known and the drop target is irrelevant (it's another unknown application)....
What are your trying to do exactly?
Avatar of thready

ASKER

lol... You're persistent Eric!  I suppose I can tell you I'm trying to get the filename of a file that is dropped into a browser.
I am trying to understand your process (and I am sure others are trying to). By better understanding the process, we might be able to propose better solution!

So you have an application and you want to detect what is being drag-and-drop to a browser but this browser is not in your application. Right?
Avatar of thready

ASKER

Correct
Then I am clueless!
Avatar of thready

ASKER

Thanks for trying  :)
Unfortunately I don't think it's possible.
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of thready

ASKER

That's not ok for commercial software.  We don't know the source window, so we'd have to invade the system and do a little too much spying.  If we owned the source then that would be ok...
Avatar of thready

ASKER

Then again, if we owned the source, we wouldn't even have to do that...
I've requested that this question be deleted for the following reason:

The question has either no comments or not enough useful information to be called an "answer".
Evering is there that is needed and since LeeTutor only knows Delete Requests, objecting is mandantory.
Avatar of thready

ASKER

Thanks for your answers!