views:

699

answers:

1

If a user copies a file to the clipboard in Windows from an Outlook email attachment, is there any way I can get the name of that file in VB.NET?

If the file is copied from Windows Explorer, Clipboard.GetFileDropList has data that I can use to get this, but that list is empty when the file is copied from an email attachment (there are just four available formats - FileGroupDescriptorW, FileGroupDescriptor, RenPrivateItem and FileContents).

It feels like this should be possible, since I can paste the file into Windows Explorer and it pastes it with the name of the attachment.

+1  A: 

It turns out that you can get the filename from the data object whose format is FileGroupDescriptor. The code is a bit arcane, though:

Dim fileName As New StringBuilder("")
Dim theStream As Stream = Clipboard.GetData("FileGroupDescriptor")
Try
    Dim fileGroupDescriptor(512) As Byte
    theStream.Read(fileGroupDescriptor, 0, 512)

    Dim i As Integer = 76
    While fileGroupDescriptor(i) <> 0
        fileName.Append(Convert.ToChar(fileGroupDescriptor(i)))
        i += 1
    End While
Finally
    If theStream IsNot Nothing Then theStream.Close()
End Try
Phillip Wells