0

I added a functionality to my C# windows form application which allows user to drag-drop file on the form so that the application can get the file path. I just exactly followed what's written on:

How to provide file drag-and-drop functionality in a Visual C# application

It is working on debug mode in Visual Studio environment. However, as soon as I try the same thing on individual exe file which is created on bin/Debug folder, the application does not react to drag-drop.

I have already tried to delete all the files on bin/Debug folder, but the result did not change.

It would be great if somebody has similar issue and solutions for this. Thank you.


Here are the codes I'm trying (after some try and errors it has changed a bit from what's written in the URL shown above, but this still works on Visual Studio but not on exe...) :

    private void OpenFile_DragEnter(object sender, DragEventArgs e)
    // enable drag-drop event
    {
        e.Effect = DragDropEffects.Copy;
    }

    private void OpenFile_DragDrop(object sender, DragEventArgs e)
    // open drag-dropped setup file
    {
        // get drag-dropped file path
        string[] s = (string[])e.Data.GetData(DataFormats.FileDrop, false);

        // open all the files
        for (int i = 0; i < s.Length; i++)
        {
            OpenSetup(s[i]);
        }
    }

Update: Another thing I found is that I can drag-drop the files on EXE from OpenFileDialog, but not from file exploler.

kk1988
  • 51
  • 6
  • There should not be any differences running from the exe and running from VS. Something you are doing is different or you are not really running the same code. First check the date on the exe to make sure it is the right date. Then make sure you do exactly the same steps when running from VS as you do when running the exe. – jdweng Nov 01 '19 at 11:21
  • Maybe the discussion [here](https://stackoverflow.com/questions/26628492/drag-and-drop-not-working-in-c-sharp-winforms-application) helps. –  Nov 01 '19 at 11:27
  • Welcome to StackOverflow. Thank you for taking the time to share your problem. But there is something missing from your question. What is your goal and your difficulty? What have you done so far? Please try to better explain your issue, your dev. environment and the data structures, as well as to share more code (no screenshot), some samples, images or sketches of the screen, and user stories or scenario diagrams. To help you improve your requests, please read the *[How do I ask a good question](https://stackoverflow.com/help/how-to-ask)* and **Questions I avoid asking** at the top right. –  Nov 01 '19 at 11:30
  • Thank you everyone for the answers. I confirm that the exe file I'm running has been created after the code modification. On Visual Studio, mouse cursor turns into "+" icon as soon as I drag a file on the form (and obviously works as I intended after the drop), but it shows "circle and slash" mark and does not allow to do drop somehow... I'm still struggling to understand how it could happen. – kk1988 Nov 01 '19 at 12:47
  • You probably ran VS elevated. D+D can't work when you drag from an elevated process to a non-elevated one. Right-click the exe file and use "Run as administrator" to reproduce. – Hans Passant Nov 01 '19 at 13:21
  • Thank you so much for your help Hans, but the issue is still not solved even having the app launched as an administrator... – kk1988 Nov 01 '19 at 14:59

0 Answers0