My C# program has a list of files that can be dragged from it and dropped into another program. My requirements are that the file be copied to a different directory first.
So, can I be notified of the drop operation so that I can only copy the file if operation succeeds? I'd rather wait till I know it needs to be copied before actually performing the copy.
Also, is it possible to know what program the drop operation is occurring in? Ideally I'd like to alter the filepath based on who or what its being dropped.
The solution to this can be in any .NET language or C/C++ with COM.
There are a few ambiguities in your question. What operation needs to be successful?
For everything you want to know about drag and drop, browse through these search results (multiple pages worth):
Raymond Chen on drag and drop
So, you intend to modify the data being dropped based on the drop target? I don't think this is possible; after all, you populate the data when the drag is initiated.
Related
I've been struggling with this for quite a while
My wpf application contains a list view, populated with file-names, which are located on a server.
I'm trying to implement drag and drop functionality, so the user can drag files from my application into his/her's local computer.
In order to do this, first i'm downloading the files into a temporary location, and then calling my application's DoDragDrop() method.
The problem is that I want to perform the download process only after the DoDragDrop method is called.
I've tried every event related to drag drop methods (GiveFeedback, ItemDrag, etc...) but nothing works
so basically what I need is an event, raised after the DoDragDrop is done
any ideas?
The current scheme is to drag a file with a special suffix, and then turn on global file monitoring to obtain the drag location of the file through monitoring.
I want to write an application in C# that only opens when the user starts to drag a file in the Windows Explorer. It doesn't matter if the file will be dropped in the app, i only want to know whenever the user drags a file in explorer, and of course, when he releases it again.
I found this article, but I don't really know where to start: Detect drag and drop operations in an external application using .Net
Since I know hardly anything about hooking, I would really appreciate it if someone could give me an example of doing that, or some ideas.
I just implemented drag&drop in my application. It goes two ways:
From my app to Windows Explorer: exports files
From Windows Explorer to my app: imports files
One side effect is that I can also drag files from my application to my application (the same window), which is not intended.
Is there a elegant way to make sure, that a drag&drop operation I started won't be accepted by my application? E.g. check if the source of the drop operation != my application?
You need to register the fact that you initiated a drag from inside your application with some sort of facility or service. If you receive a drop on your application, ask the facility/service if the drag was initiated within your application. If so, discard. Reset the facility/service afterwards (in any case).
I just figured out a way to do this.
Now I set two types of data on my drag&drop data object:
The file names I want to export
A Unicode-Text object containing the name of my application
In my Drop-handler I check if a Unicode-Text object is present and if it contains my application's name. If so, I abort the drop operation.
As is well-known, WPF still doesn't supply a folder selection dialog (unless WPF4 has one that I've missed). In the meantime, I am using System.Windows.Forms.FolderBrowserDialog.
Unfortunately, this dialog only has a folder tree, OK, Cancel, and an optional "Make New Folder" button. The usability is poor. Particularly, it is terrible when trying to select a network folder. The only way to select the folder is to expand the "Network" base.. which on many corporate systems/networks, will begin a long delay and ultimately yield an unacceptably long list.
I would like a text entry field which would allow the user to start navigation at a particular location.. such as a particular computer/folder.. such as is possible in the file browse dialog.
Has anyone done such a thing? Is this a way to extend the standard System.Windows.Forms.FolderBrowserDialog, or will I have to create my own?
Thanks.
Vista Bridge provides managed wrappers for the new Vista dialogs with fallback support when running on older OS. These file dialogs are preferrable to either the stock WPF or WinForms ones.
The Windows API Code Pack provides managed wrappers for Windows 7 features.
I think you should create your own, no default folder dialog implement something like this. If I'm not wrong, java too doesn't allow such possibility.
I normally create the "open folder dialog" button near a textbox where the path can be written manually (when the folder dialog button is closed with ok button simply fill that textbox), that's the easiest way.
Your type of dialog should be created, on the good side you can at least sell it because it looks nice and helpful. Or maybe you can find something similar on the web (previous payment by the way).
Another thing, all folders dialog are very slow, at least on windows XP, maybe is "impossible" to reduce those delays, you should do some searches to avoid this problem (multi-threaded dialog which gather information while giving possibility to start navigating through directory tree is the only thing i can think about).
Hope this will be helpful
EDIT:
Maybe this has some sort of utility,
http://www.ssware.com/fldrview.htm
it looks cool but doesn't have all features you want, I think it doesn't exist as you hope
You wrap native code and use the SHBrowseForFolder function:
http://msdn.microsoft.com/en-us/library/bb762115(v=vs.85).aspx
Or starting with Vista you could use create a COM object with the id "CLSID_FileOpenDialog" (native code, too):
http://msdn.microsoft.com/en-us/library/bb776913(VS.85).aspx
Both of those provide a text input area where you can type in UNC paths.
I have an application that runs elevated (yes, it has to be elevated) but it needs to detect when another application is dragging an object over it. My application doesn't care what the object is, it doesn't want to receive the object, it just needs to know if something is being dragged. In a normal application this isn't an issue, but because my application is elevated it doesn't receive any of the standard drag/drop events from lower privilege applications. Is there a programmatic way to detect whether the cursor is involved in a drag/drop operation?
To do "system wide" drag and drop, I think you have to go the OLE way.
Drag and Drop (OLE)
Also see the "Data Objects and Data Sources (OLE)" link at the bottom of the article.