11-01-2012, 04:20 PM
I have never worked with the Clipboard object before. So, I found this code snippet online. I hope it helps!
[code2=vbnet]Public Function ClipboardCopyFiles(ByVal Files() As String) As Boolean
Dim dataObject As New DataObject
Dim varObject(0) As String
Dim fileName As String
Dim idxFile As Integer
Dim scriptingFile As Scripting.File
Dim fileSysObject As New Scripting.FileSystemObject
Try
'Clipboard.SetDataObject(New DataObject)
For idxFile = LBound(Files) To UBound(Files) - 1
If Not (Files(idxFile) Is Nothing) Then
scriptingFile = fileSysObject.GetFile(Files(idxFile).ToString())
fileName = scriptingFile.ShortPath
End If
Next
'//
varObject(0) = fileName
dataObject.SetData(DataFormats.FileDrop, False, varObject)
Clipboard.SetDataObject(dataObject)
'//
ClipboardCopyFiles = True
Catch ex As Exception
MsgBox(ex.Source & " : " & ex.Message)
ClipboardCopyFiles = False
Throw ex
End Try
End Function[/code2]
[Copied from <!-- m --><a class="postlink" href="http://www.developerfusion.com/thread/44352/copy-file-to-clipboard-and-use-clipboard-object-in-vbnet-2/">http://www.developerfusion.com/thread/4 ... n-vbnet-2/</a><!-- m -->]
[code2=vbnet]Public Function ClipboardCopyFiles(ByVal Files() As String) As Boolean
Dim dataObject As New DataObject
Dim varObject(0) As String
Dim fileName As String
Dim idxFile As Integer
Dim scriptingFile As Scripting.File
Dim fileSysObject As New Scripting.FileSystemObject
Try
'Clipboard.SetDataObject(New DataObject)
For idxFile = LBound(Files) To UBound(Files) - 1
If Not (Files(idxFile) Is Nothing) Then
scriptingFile = fileSysObject.GetFile(Files(idxFile).ToString())
fileName = scriptingFile.ShortPath
End If
Next
'//
varObject(0) = fileName
dataObject.SetData(DataFormats.FileDrop, False, varObject)
Clipboard.SetDataObject(dataObject)
'//
ClipboardCopyFiles = True
Catch ex As Exception
MsgBox(ex.Source & " : " & ex.Message)
ClipboardCopyFiles = False
Throw ex
End Try
End Function[/code2]
[Copied from <!-- m --><a class="postlink" href="http://www.developerfusion.com/thread/44352/copy-file-to-clipboard-and-use-clipboard-object-in-vbnet-2/">http://www.developerfusion.com/thread/4 ... n-vbnet-2/</a><!-- m -->]