hii, i'm having this problem in ma head for months till i decided to ask it here (of course i digg every search engine). The question is simple: I'm making an app like winzip (an extractor) and i successfully coded dragging a file in and opening. But i now need to drag the files out, like in winzip in which i can drag and drop a file on to any folder directly. But how to implement that into my program? Please HELP! Thnkxx
evryone, i figured it out (cheating really) and i'll post it here n submit as a tut for future use --------------------------------- First i muz tell tat drag out thing can be easily done using the doDragDrop func() but the problem is it always have a custom event. Like just to copy a file which is already EXIST, or move like so. But most of the time the need is to dodragdrop for a virtual file. ex: in ma project which is a decompressioner i wanted to get the target path and then decompress the file to that path. Because there's no possible way of to create the file before dragging off! So i cnt use the normal func as: (1) As i cannot provide my own codes for that or get the target path (2) I cannot delay the process to decompress the file So i found a CHEATING method. [The original idea is not mine, i saw da idea and just coded it suitably ) --------------------------------------------------------- The idea behind is to add some filesystemwatchers to Watch weather a SPECIFIC file to created and WHERE. So the theory is i'm going to make a 'fake' file drop (just tel the user and the system that i dropped a file) but instead of dropping the real file i use a predifined file. (with a remarkable ext.) So when the file is created the fileSystemWatcher FIRES! and tell us the target dir! Lets start: First we need to setup filesystem wacthers and the form load: Code: Public Sub setupFSMs() ' This is the main sub that prepares the filesystemwatchers. ' DONOT edit the code. ' Replace .antf2 with a unique ext. Dim Drives() As IO.DriveInfo = IO.DriveInfo.GetDrives For i As Integer = 0 To Drives.Length - 1 If Drives(i).DriveType = IO.DriveType.Fixed Then If Drives(i).IsReady Then Dim FSM As IO.FileSystemWatcher = New IO.FileSystemWatcher(Drives(i).RootDirectory.FullName, "*.antf2") AddHandler FSM.Created, AddressOf OnChanged FSM.IncludeSubdirectories = True FSM.EnableRaisingEvents = True End If End If Next End Sub private sub form_load(blah) setupFSMs end sub Above initiate the fileSystemWatchers. Note the ext. i have used. its "antf2" which i felt like an uncommon one remeber to use your own one as i dont want ma prog go messing around Now the code to say What To Do when we find a drop of that file. Code: Sub OnChanged(ByVal source As Object, ByVal e As IO.FileSystemEventArgs) ' Specify what is done when a file is created. ' NOTE this runs on a seperate thread! output = IO.Path.GetDirectoryName(e.FullPath) My.Computer.FileSystem.DeleteFile(output.Trim(quote) & "\tmp_donot_delete.antf2") 'This is to prevent the file being there too much. msgbox(output) 'Add your code here End Sub Add the actionyou need in 'Add your code here part PLEASE note that this action runs on a seperate thread so be creaful not to add actions with cross-thread references. Now to add the real part, where the file is dragged out Here i have used a lstView and i coded in the itemDrag. Code: If lstMain.SelectedItems.Count > 0 Then Dim fileas As String() = New [String](0) {} fileas(0) = My.Application.Info.DirectoryPath & "\tmp_donot_delete.antf2" dta = New DataObject(DataFormats.FileDrop, fileas) dta.SetData(DataFormats.StringFormat, fileas) DoDragDrop(dta, DragDropEffects.Copy) End If See what happened? I just copied the file "tmp_donot_delete.antf2" from the ma prog dir to the target dir. (NOTE: tmp_donot_delete.antf2 is the file name i've given. You'll need to have this file created evrythime you run your prog. Of corse thats simple and you can add hidden + system attribs to make sure this file is hidden) So that way, when user drag out the file, tmp_donot_delete.antf2 will copy to the target dir and the FileSystemWatcher will catch it then get the target dir in the output variable. So you can use it on your wish! I'm sorry for the bad gramer n all mistakes. Please feel free to ask on any matter [Credits goes for the one who really thought of this idea] Final Notes: This method is not 100% good, but easy to use. If you really need it in the professional way you'll have to extend your searches on shellExts