Copy file to clipboard and use Clipboard object in VB.NET (#2)

  • 14 years ago
    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





























Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“I invented the term Object-Oriented, and I can tell you I did not have C++ in mind.” - Alan Kay