0

I'm developing an application to read XML files, get its data and populate some field. SO, I've implemented two ways to get the file: through a command button and through the drag and drop form event. Everything is OK if I use a file stored in a folder in my computer. I can drag the file, the cursor changes its appearance to the copy effect etc. However, when I try doing it dragging a file as an attachment of Outlook (my version is the 2010), I see that the cursor assumes the forbidden effect and the file is not read.

Please, see below the implementation I did, which is working only for files stored in a folder in my computer. I would like to know what more I have to implement to allow drag a file from Outlook.

Thank you in advance.

    Private Sub FrmJIG_DragDrop(sender As Object, e As DragEventArgs) _
    Handles Me.DragDrop
    Dim files() As String = e.Data.GetData(DataFormats.FileDrop)
    Dim filestype() As String

    filestype = e.Data.GetData(DataFormats.FileDrop)
    Dim sReader As New StreamReader(filestype(0))

    'get the filename from the file without the path
    Dim file_name As String = Path.GetFileName(filestype(0))

    'check the extension of the file
    If Path.GetExtension(filestype(0)).ToLower() = ".xml" Then
        'Read the xml file
        For Each path In files
            ReadXMLFile(path)
        Next
    Else

        'warning about the file type
        MessageBox.Show("Only XML files are supported!", "Warning!", _
MessageBoxButtons.OK, _
    MessageBoxIcon.Warning)
    End If
End Sub

Private Sub FrmJIG_DragEnter(sender As Object, e As DragEventArgs) _
Handles Me.DragEnter

    'change the cursor  type to drag and drop type
    If e.Data.GetDataPresent(DataFormats.FileDrop) Then
        e.Effect = DragDropEffects.Copy
    End If
End Sub
Charles
  • 50,943
  • 13
  • 104
  • 142
JoseFernandes
  • 33
  • 1
  • 5

1 Answers1

0

Please try with

Private Sub FrmJIG_DragEnter(sender As Object, e As DragEventArgs) _
Handles Me.DragEnter

    'change the cursor  type to drag and drop type
    If e.Data.GetDataPresent(DataFormats.FileDrop) or e.Data.GetDataPresent("FileGroupDescriptor") Then
        e.Effect = DragDropEffects.Copy
    End If
End Sub
Eduardo Molteni
  • 38,786
  • 23
  • 141
  • 206