Question Drag file to the exe file

LeonLanford

Active member
Joined
Dec 2, 2008
Messages
28
Programming Experience
Beginner
Hi.. I want to ask how to drag file to exe file?

I'm making upload program now, I can drag the files to the data grid view. Now I want to drag files to the exe file

So if I drag 2 files to the program upload.exe, the program automatically opens and have 2 files inserted to the data grid, for now if I drag the files to the upload.exe, the program only opens but the data is not in the data grid view..

here's code how I get the data inserted to the data grid view, I've seen program like this that I only have to drag the files to the exe and the data is already automatically inserted to the data grid..

VB.NET:
    Private Sub dgv_uplot_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles dgv_uplot.DragDrop
        If e.Data.GetDataPresent(DataFormats.FileDrop) Then

            MyFiles = e.Data.GetData(DataFormats.FileDrop)

            total = MyFiles.Length

            browse("drag")

        End If
    End Sub

    Private Sub dgv_uplot_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles dgv_uplot.DragEnter

        If e.Data.GetDataPresent(DataFormats.FileDrop) Then
            e.Effect = DragDropEffects.All
        End If

    End Sub

Hope someone can help me, thanks.. :D
 
files dragged to the exe can be retrieved from the Environment.GetCommandLineArgs() array. The first element in the array is the exe file itself and the rest is the commandline switches and/or files passed to it.

Once you have the files from the args (probably just store them in the MyFiles array) all you need to do is populate the grid the same as a file drop on the already running app.
 
VB.NET:
Dim Args() As String = Environment.GetCommandLineArgs()
For Counter As Integer = 0I To Args.UpperBound(0I)
  Messagebox.Show(Args(Counter))
Next Counter
 
Back
Top