We help IT Professionals succeed at work.

recognizing a file drop from Groupwise

codefinger
codefinger asked
on
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?

Thanks.
Comment
Watch Question

Scott KunauSr. Consultant/Managing Partner

Commented:
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?

Scott

Author

Commented:
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); 
       stream.Close(); 
   } 
 
   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 
          fileIn.Close(); 
      } 
   } 
 
   File.Delete(strFilename); 
}

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
        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