• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 223
  • Last Modified:

Problem with simple file drag and drop. Help??!!

Hi there. I have a very simple form. What I want to do is allow the user to drag an image file into the small form, have the form use the shell command to create a network drive, copy the drag&drop file to the drive, and then close the created drive. Im having a few probs though running the shell command, and also gett the file I need to operate on.

The code I have is simple but close I think. Can anyone tell me what Im doing wrong?

    Private Sub frmDrop_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Me.DragDrop
        Try
            'Exception thrown here over permissions. How can I execute these commands?
            Shell("Net use n: /Delete", AppWinStyle.Hide, True)
            Shell("net use n: \\192.168.1.1\c$\inetpub\wwwroot\iCentral\banners\advision\  password /USER:administrator", AppWinStyle.Hide, True)

            If e.Data.GetDataPresent(DataFormats.FileDrop) Then
                'Perform a copy command here
'also how do I get the file handle so that I can copy it to the n drive?

            End If


        Catch ex As Exception
            MsgBox(ex.Message)
        Finally
            Shell("Net use n: /Delete", AppWinStyle.Hide, True)
        End Try
       
    End Sub

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


        e.Effect = DragDropEffects.Copy

    End Sub
0
Slimshaneey
Asked:
Slimshaneey
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Here is how to get the FileName:

    Private Sub frmDrop_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Me.DragEnter
        If (e.Data.GetDataPresent(DataFormats.FileDrop)) Then
            e.Effect = DragDropEffects.Copy
        Else
            e.Effect = DragDropEffects.None
        End If
    End Sub

    Private Sub frmDrop_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Me.DragDrop
        Dim a As Array = DirectCast(e.Data.GetData(DataFormats.FileDrop), Array)
        If Not (a Is Nothing) Then
            Dim fileName As String = a.GetValue(0).ToString()

            ' do somethin with fileName...

        End If
    End Sub
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now