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
C++Windows 7C#

Avatar of undefined
Last Comment
thready

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
jkr

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Éric Moreau

is that C++ or C# that you need? Winforms or WPF?
thready

ASKER
C#   :-)
Thanks jkr! ! !
thready

ASKER
I'll try this tomorrow morning!
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Éric Moreau

Winforms or WPF?
thready

ASKER
Wpf...
Éric Moreau

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

⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
thready

ASKER
I don't want to detect drops, I want to detect the start of drag only.
Éric Moreau

My code lets you preview before you drop. The drop is not handled. What are your trying to do exactly?
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!
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
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...
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)....
Éric Moreau

What are your trying to do exactly?
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
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.
Éric Moreau

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?
thready

ASKER
Correct
Your help has saved me hundreds of hours of internet surfing.
fblack61
Éric Moreau

Then I am clueless!
thready

ASKER
Thanks for trying  :)
Unfortunately I don't think it's possible.
SOLUTION
Éric Moreau

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
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...
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
thready

ASKER
Then again, if we owned the source, we wouldn't even have to do that...
LeeTutor

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".
jkr

Evering is there that is needed and since LeeTutor only knows Delete Requests, objecting is mandantory.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
thready

ASKER
Thanks for your answers!