We help IT Professionals succeed at work.

recognizing a file drop from Groupwise

codefinger asked
I want the users to be able to open a Groupwise email and drag a file attachment on to a list box in my winforms application.  The application recognizes what has happened and takes possession of the file, or a copy of it, for further processing.

How can this be done?

Watch Question

Scott KunauSr. Consultant/Managing Partner

I just opened a GroupWise message with an .xls file attachment and dragged it to my desktop.  Then I double-clicked on it and it opened just fine.

I'm not sure what you mean by "list box in my winforms application".  Perhaps you have a screen capture of the list box?



By "list box in my winforms application", I mean the application I am coding.

According to my Googling, the code attached below MAY do what I need, but it is in VC.Net where I have no skill.   If some one could re-write it in VB.NET,  and it works, that will be my solution.

private void control_DragDrop(object sender, DragEventArgs e) 
   string strFilename = null; 
   //something about the act of reading this stream creates the file in your temp folder(?) 
   using (MemoryStream stream = (MemoryStream)e.Data.GetData("attachment format", true)) 
       byte[] b = new byte[stream.Length]; 
       stream.Read(b, 0, (int)stream.Length); 
       strFilename = Encoding.Unicode.GetString(b); 
       //The path/filename is at position 10. 
       strFilename = strFilename.Substring(10, strFilename.IndexOf('\0', 10) - 10); 
   if (strFilename != null && File.Exists(strFilename)) 
      //From here on out, you're just reading another file from the disk... 
      using(FileStream fileIn = File.Open(strFilename, FileMode.Open)) 
          //Do your thing 

Open in new window

I worked it out....
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
            e.Effect = DragDropEffects.None
            Exit Sub
        End If

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


Open in new window