Write a binary file directly to the clipboard
Is it possible to write a binary file directly to the clipboard in .NET? (Rather than write it to a file and then copy it?) the file is not an executable but will be pasted to the desktop\folder for example.
Dim connection As New SqlConnection("Data Source=SERVER\SQL2008;Initial Catalog=NorthPole;Integrated Security=True")
Dim command As New SqlCommand("SELECT pcfFile FROM Items WHERE pcfFileName=@Filename", connection)
command.Parameters.AddWithValue("@Filename", filename)
connection.Open()
Dim FileData As Byte() = DirectCast(command.ExecuteScalar(), Byte())
Dim fileStream As New FileStream(System.IO.Path.GetTempPath & FileName, FileMode.Create)
fileStream.Read(FileData, 0, CInt(fileStream.Length))
fileStream.Close()
Clipboard.SetDataObject(New DataObject(System.Windows.Forms.DataFormats.FileDrop, File开发者_如何学CData), True)
connection.Close()
I'm not sure this is possible. By reading all the formatted data off of the Clipboard.GetDataObject, I was able to glean this from the information ( although it is VERY unclear to me ).
This was ran with an executable named "LightMap.exe" in the root of C:\
"⊘" denotes a byte of 0.
Format "Shell IDList Array" contains: "⊘⊘⊘⊘⊘⊘;⊘⊘⊘⊘P�O� �:i��⊘+00�⊘/C:\⊘⊘⊘⊘⊘⊘⊘⊘⊘⊘⊘⊘⊘⊘⊘⊘⊘⊘⊘⊘⊘N⊘2⊘⊘`⊘⊘-=`� ⊘LIGHTY~1.EXE⊘⊘2⊘⊘⊘�-={�-={�⊘⊘⊘L⊘i⊘g⊘h⊘t⊘y⊘M⊘a⊘p⊘.⊘e⊘x⊘e⊘⊘⊘⊘⊘⊘"
Format "FileDrop" contains: "C:\LightyMap.exe"
Format "Preferred DropEffect" contains: "⊘⊘⊘"
Format "Shell Object Offsets" contains: "⊘⊘⊘�⊘⊘⊘⊘⊘⊘⊘⊘⊘⊘"
Format "FileName" contains: "C:\LIGHTY~1.EXE"
Format "FileNameW" contains: "C:\LightyMap.exe"
As you can see, there isn't a whole lot of useful information here towards what you want to do, but it does give a glimpse of the internals.
For instance, "Shell IDList Array" seems to have the path embedded in an 8.3 friendly form and a 0 byte delimited path towards the end, but if the path is large ( probably to exceed 88 bytes, such as C:\Documents And Settings\username\Desktop\LightyMap.exe ), it only contains the file name but not the path while the FileName and FileNameW remain correct.
Formats with 0 bytes are IO.MemoryStream, text will either be String( ) or String, and so on.
I do know that the offsets are related to if it should cut or copy the file, but aside from that, the rest is a mystery.
精彩评论