Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Copy File to Clipboard

96 views
Skip to first unread message

L Anthony Johnson

unread,
Nov 5, 2002, 12:20:23 PM11/5/02
to
Does anyone have an example of copying a file to the clipboard? I've
perused help , but can't find anything besides adding text to the clipboard.

Landry


VBDotNet Team [MS]

unread,
Nov 7, 2002, 4:09:00 PM11/7/02
to
We're assuming you mean that you want to handle copy/pasting files
themselves (like Explorer does), and not simply that you're trying to copy
the file's contents to the clipboard as text (if you wanted that, you would
just read in the file and copy it as a string to the clipboard).

The following code shows how to use the DataFormats.FileDrop format, which
is what you use to copy/paste files. You might also look at
http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q306969&, which
explains how to allow dropping of files via drag/drop.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
TextBox1.Text = ""
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnPaste.Click
TextBox1.Text = ""
Dim DataObject As DataObject = Clipboard.GetDataObject()
If DataObject.GetDataPresent(DataFormats.FileDrop) Then
'There's a file there
Dim Files() As String = DataObject.GetData(DataFormats.FileDrop)
Dim i%
For i = 0 To UBound(Files)
TextBox1.Text &= Files(i) & vbCrLf
Next
End If
End Sub

Private Sub btnCopy_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCopy.Click
Dim DataObject As New DataObject()
Dim Files() As String = Split(TextBox1.Text, vbCrLf)
DataObject.SetData(DataFormats.FileDrop, Files)
Clipboard.SetDataObject(DataObject)
End Sub

Stephen and Shamez [MS]
--
This posting is provided "AS IS" with no warranties, and confers no rights.

"L Anthony Johnson" <pps...@nospamm4m3bellsouth.net> wrote in message
news:OtlUBAPhCHA.1652@tkmsftngp11...

0 new messages