BP Forums
Copy file to clipboard - Printable Version

+- BP Forums (https://bpforums.info)
+-- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=55)
+--- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=56)
+---- Forum: VB.NET (Visual Basic 2010/2008) (https://bpforums.info/forumdisplay.php?fid=8)
+----- Forum: Programming Help (https://bpforums.info/forumdisplay.php?fid=9)
+----- Thread: Copy file to clipboard (/showthread.php?tid=647)



Copy file to clipboard - brco900033 - 09-15-2012

Hi!
I have a question already. How can I copy a file to the clipboard? Not only the path or filename, but the whole file so you can actually paste the file onto your desktop or something.

Thanks in advance


Re: Copy file to clipboard - Snake_eyes - 11-01-2012

Why do you need to copy the file to the clipboard when there are many methods to simply copy or move a file from one location to another?


Re: Copy file to clipboard - brandonio21 - 11-01-2012

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


Re: Copy file to clipboard - brco900033 - 11-02-2012

I tried and it worked for me. Thanks!


Re: Copy file to clipboard - brandonio21 - 11-04-2012

brco900033 Wrote:I tried and it worked for me. Thanks!
No problem, glad we could solve your problem!