We help IT Professionals succeed at work.

catch multiple file attachments from Groupwise in winforms vb.net

The code attached will process ONE file dragged from a Groupwise message on to a winforms ListBox.   What I need now is how to discover and process them if the user drags over several files from Groupwise at one time.
Dim ob As System.Object = Nothing
        Dim ms As System.IO.MemoryStream

        ms = e.Data.GetData("attachment format", True)
        Dim b(ms.Length) As Byte
        ms.Read(b, 0, b.Length)

        strfilename = System.Text.Encoding.Unicode.GetString(b)
        '//The path/filename is at position 10.

        strfilename = strfilename.Substring(10)

        strfilename = ctrl.GetLongPathName(strfilename)


        If strfilename.EndsWith("pdf", StringComparison.CurrentCultureIgnoreCase) Or _
           strfilename.EndsWith("gif", StringComparison.CurrentCultureIgnoreCase) Then
            e.Effect = DragDropEffects.Copy
        Else
            e.Effect = DragDropEffects.None
            ms.Close()
            Exit Sub
        End If

        If Not System.IO.File.Exists(strfilename) Then
            MsgBox("File not found")
        Else
            MsgBox("File was found")
        End If

        ms.Close()

Open in new window

Comment
Watch Question

Most Valuable Expert 2012
Top Expert 2014

Commented:
How do you select multiple attachments? When I added the functionality in my project to accept Outlook attachment dropped on it, I thought about multiple attachments. But I could not drag multiple attachments from Outlook.

Author

Commented:
Groupwise may have several files attached to a single email.  To select multiple attachments, click on one, hold down shift key (or ctrl key), click another, then drag files to destination.

.  
Trick is to split on the colon, then assemble the file names...see attached
Private Sub ListBoxPageFiles_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListBoxPageFiles.DragDrop
        Dim filestocopy() As String
        Dim strfilename As String = Nothing
        Dim str_path As String = Nothing
        Dim fifo As System.IO.FileInfo = Nothing
        Dim created_date As DateTime = Nothing

        If ctrl.AllowDrop Then
            e.Effect = DragDropEffects.Copy
        Else
            e.Effect = DragDropEffects.None
        End If



        Dim ms As System.IO.MemoryStream
        ms = e.Data.GetData("attachment format", True)
        If ms Is Nothing Then
            e.Effect = DragDropEffects.None
            Exit Sub
        End If

        Dim strfile As String = Nothing
        Dim b(ms.Length) As Byte
        ms.Read(b, 0, b.Length)
        Dim splitchar As String = Nothing
        Dim strdrive As String = Nothing

        strfilename = System.Text.Encoding.Unicode.GetString(b)
        
        Dim splitfiles() As String
        splitfiles = strfilename.Split(":")
        Dim cntr As Integer = 0

        If splitfiles.Length > 2 Then
            splitfiles(0) = strfilename.Substring(10)
            splitfiles(0) = ctrl.GetLongPathName(splitfiles(0))
            strdrive = splitfiles(0).Substring(0, 2)
            For cntr = 1 To splitfiles.Length - 1
                splitfiles(cntr) = strdrive & splitfiles(cntr)
                splitfiles(cntr) = ctrl.GetLongPathName(splitfiles(cntr))
            Next
            For cntr = 1 To splitfiles.Length - 1
                If System.IO.File.Exists(splitfiles(cntr)) Then
                    If Not ctrl.AddFormPage(splitfiles(cntr), lex) Then
                        MsgBox(lex.FullMessage, MsgBoxStyle.Critical, HPFMain.TitleBar)
                    End If
                End If
            Next
        Else
            strfile = ctrl.GetLongPathName(strfilename.Substring(10))
            If strfile.EndsWith("gif") Then
                If Not ctrl.AddFormPage(strfile, lex) Then
                    MsgBox(lex.FullMessage, MsgBoxStyle.Critical, HPFMain.TitleBar)
                End If
            End If
        End If
        


        ms.Close()
        ms.Dispose()



    End Sub

Open in new window