I'm trying to achieve functionality similar to winzip/winrar, etc. I have a Treeview that displays the contents of a package (System.IO.Packaging). I want to be able to drag and drop a file or folder from the TreeView onto an explorer window or the desktop, etc. My problem is that I have to call DoDragDrop before I know if the object was actually even dropped. That means to create the DataObject with the FileDrop type, I must extract those contents of the package out to a temporary area and then provide that path to the DataObject before calling DoDragDrop. If the user doesn't drop on a capable container or cancels the drop, the overhead of extracting those contents is wasted. I've noticed that winzip does not actually create the temporary file until the drop occurs on a valid target. I've checked the DataFormats provided by the WinZip drop and they are normal FileDrop, FileNameW, FileName and Shell IDList Array. The first three simply hold a string to the temporary location that winzip extracted that file to. I'm not sure what the last one does.
Long story short, I want to be able to avoid extracting the contents until I know the drop location was valid. Is there a callback to figure out the drop location? Any suggestions would be extremely helpful.
System.Windows.DragDropEffects de = DragDrop.DoDragDrop(treeview1, dataObj, System.Windows.DragDropEffects.Move);
I've tried this with an application similar to an FTP server - I wanted to start downloading only after the user actually dropped the item. Unfortunately I found no way to do this using managed code only.
The way WinZip probably does it is by receiving COM callbacks (please forgive me if I'm using the wrong words here) and you'd have to create a managed wrapper around the native COM object in order to receive such callbacks yourself.
It's certainly possible, but I gave up and embedded a FolderTreeView thingie in my application to catch the drop events myself :/
Related
I would like a particular type of file (eg. Namefile.ext2) read all the names preceded by a #
Sample contents of the file:
#nameone
#nametwo
#namethree
When I click the right mouse button on the ext2 file extension beyond the standard options (like: open, properties, etc ...) I would like to be:
contents of the file > nameone
nametwo
namethree
Then, select the item (eg. nameone) pass this parameter to my program running in the background / or services
Do you need to modify the registry somehow? I will be grateful for tips on how to achieve the desired effect.
What you are asking about is called 'shell extension'. Basically it requires some knowledge of COM objects programming, but .NET made things a bit easier in that matter.
Shortly: you have to develop a piece of code which will reads the file and generates menu items dynamically (which may be tricky but possible). That code needs to be registered in the system as COM object.
Before it starts working you have to associate file extension with COM object you created.
Perhaps this article can explaint it a bit more:
http://www.codeproject.com/Articles/512956/NET-Shell-Extensions-Shell-Context-Menus
I'm currently working on a project to provide interop between two unrelated pieces of software. I need to pass the data from a textBox/textBoxes, into a textBox of the other said app.
My current idea is to find the handle of the target control, make it active, and enter the data by copying it to the clipboard, and pasting it via:
Clipboard.SetText(textBox1.Text, TextDataFormat.Text);
SendKeys.SendWait("^V");
As textBoxes have no 'caption', handles are dynamically assigned on the process start, and class names are appended with various data regarding the process, is it possible to get a handle for an object within a window via some sort of indexing? I'd be more than willing to find the correct handle by trial and error if need be, as long as it would be consistent for every instance of the application.
Thanks in advance
A.
If you don't have any other choice.. to make this easier, you can use AutoIT.. I had to do something like this a very long time ago. AutoIT. They have a DLL for .net Applications, so you can use their functionality without having to use their scripts. If you do use their scripts.. they also have an option that will turn their script into an executable.
Following my scenario.
I got an Application which loads a Filestructure (Folders, Files) from a Database into a WPF ListView. Now I'd like to grab a file from this ListView, drag it over my Desktop (or some open explorer window) and drop it there. Basic Drag and Drop, nothing fancy. This sounds like a "standard" function for a windows application - but google won't help.
So how can I achieve this? Interops?
Thanks
Edit: Thanks for the solution, I still had to do some googling. Here's my complete solution.
DragDrop.DoDragDrop can do this as long as you pass it an appropriate DataObject.
First copy the files somewhere. You can use System.IO.Path.GetTempPath() if you don't have anywhere better.
Next create a string array containing the full paths to the files and do the following:
string[] paths = ...;
DragDrop.DoDragDrop(this, new DataObject(DataFormats.FileDrop, paths),
DragDropEffects.Copy);
It is actually possible to do this without pre-copying the files but that gets into some complicated IDataObject interactions, so unless your files are potentially very large and aren't already in the filesystem I would try this method first.
I have a query about drag-drop in C# using .NET.
My issue is with remote files. I have a list of remote files which the user can drag into an explorer window (desktop, etc). When such a drag occurs I want to be able to download the file and write it to the drop location.
The normal method of dragging files:
private void StartDragDrop(string FileToDrag)
{
MyControl.DoDragDrop(new DataObject(DataFormats.FileDrop, FileToDrag), DragDropEffects.Copy);
}
...does not suit my needs as I will not have the file data to populate the drag-drop object until after the DROP.
I have seen this functionality in many FTP clients and such.
Thanks in advance wizards.
It appears there is no logically straight forward method to do such a thing.
But there is a work around (with a substantial amount of work for such basic functionaliy) that can be found at codeproject.
If anyone finds a tidy way of doing it, let me know, I'd be intrigued.
Is there a way to modify the behavior of the OpenFileDialog so that it looks inside the files in the folder it opens to and then ignores certain ones based on their content?
One example would be to open to a folder full of Zip files but only show the ones that contain a certain file.
From the documentation, there's the HookProc but I'm not exactly sure how I'd use it.
Please note that if it is possible, I realize that it'll be a relatively slow operation. At the moment I'm not concerned about performance.
Thanks!
I wouldn't dismiss the complexity of the OpenFileDialog. It's not so easy to build one that really works. When you do build your own, it's not the "normal" dialog and as a result it confuses users. This is true even if you do it well, which is difficult. So I'd suggest you stick to extending what is already there, rather than writing something new.
Check this article for an extension of OFD that might/could be tweaked to do exactly what you want. There's a callback that you write in C# that responds to path selection.
Related: FolderBrowserDialogEx is a similar extension on FolderBrowserDialog. Despite the name, you can configure it to search for files, as well as folders. There's a callback that gets invoked when something (a folder, a file) is selected, and within that callback you can do what you need to do. For example, peek inside the files within a folder and populate the list of files to display with only those files.
Another option you might consider is the dialog library from Ookii. This is an open source implementation of the OpenFileDialog, and it includes COM wrappers for all the new dialog stuff in Vista. Using that library you can pop a Vista OpenFileDialog and receive events from the IFileDialogEvents interface, in C# code. One such event is OnFolderChange(). Within the handler you could call IFolder.GetFolder() which will get you an IShellItem, which gives you the folder the user is changing to. The next step would be to itemize and potentially filter the set of files, which is an exercise I will leave to the reader...
No, you would have to implement your own functionality for that. But to be honest, the OpenFileDialog really doesn't do a whole lot anyway. To be honest, yeah, you probably could hook into it, but you'd be doing a lot of work for nothing when the real work is to inspect the content of the files and then you can write your own simple OpenFileDialog class on top of that.
You might find this question helpful regarding listing contents of zip files:
How to list the contents of a .zip folder in c#?
(Note, you could potentially thread it to improve performance, just don't span many threads)
You can probably use the Windows API Code Pack (comes with the source). The Common File dialogs feature exposes a lot more functionality of file dialogs than the versions in Winforms/WPF.
http://code.msdn.microsoft.com/WindowsAPICodePack