[RESOLVED] [02/03] Copy Multiple Files To Clipboard
Using this code
Quote:
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
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...
Re: [02/03] Copy Multiple Files To Clipboard
Thanks a lot.
Quote:
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.
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...