Results 1 to 4 of 4

Thread: [RESOLVED] [02/03] Copy Multiple Files To Clipboard

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    675

    Resolved [RESOLVED] [02/03] Copy Multiple Files To Clipboard

    Using this code
    im DataObject As New DataObject
    Dim tempFileArray(0) As String
    'NOTE THAT IT MUST BE PASSED AN ARRAY!!!
    tempFileArray(0) = activeListView.SelectedItems(0).Tag
    DataObject.SetData(DataFormats.FileDrop, False, tempFileArray)
    Clipboard.SetDataObject(DataObject)
    from this thread
    http://vbforums.com/showthread.php?t...file+clipboard
    I was able to copy a file and then paste it anywhere on my machine.

    However, I need to be able to copy multiple files at once. Does anyone know how to accomplish this? I tried creating an ArrayList; didn't work. If I change the declaration to Dim tempFileArray(X) As String (X being ANY number), and change NOTHING else, it quits working. This, obviously, prevents from copying multiple files (or even one, for that matter). Sometimes it makes the Paste option enabled, but pasting produces no results.

    Any ideas? I am stumped.
    Thanks
    VB.Net 2008
    .Net Framework 2.0

    "Must you breathe? 'Cause I need heaven..."

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [02/03] Copy Multiple Files To Clipboard

    use an arraylist, and then cast it to an array of strings.

    This works fine.

    Code:
            Dim DataObject As New DataObject
            Dim tempFileArray As New ArrayList
            'NOTE THAT IT MUST BE PASSED AN ARRAY!!!
            tempFileArray.Add("C:\test1.txt")
            tempFileArray.Add("C:\test2.txt")
            DataObject.SetData(DataFormats.FileDrop, False, DirectCast(tempFileArray.ToArray(GetType(String)), String()))
            Clipboard.SetDataObject(DataObject)
    Note: replace my tempFileArray.Add() lines with your own.. I used test files on my C drive root...

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    675

    Re: [02/03] Copy Multiple Files To Clipboard

    Thanks a lot.

    DirectCast(tempFileArray.ToArray(GetType(String)), String())
    That's the little bit that I was missing. I am pretty functional in VB (it's my job), but there are many intricacies that I do not know.

    Thanks again.
    VB.Net 2008
    .Net Framework 2.0

    "Must you breathe? 'Cause I need heaven..."

  4. #4
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [RESOLVED] [02/03] Copy Multiple Files To Clipboard

    Just so you know, its MUCH easier in .NET 2.0 because you can use generics...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width