listview and arrays 
Author Message
 listview and arrays

I have a listview that shows files. I want to be able to move some selected
files to another folder. I'm doing this by selecting the files and using a
menu item on a context menu.

This is the code I have:

string[] selectedItems = new string[lvFileList.SelectedItems.Count];
lvFileList.SelectedItems.CopyTo(selectedItems, 0);

foreach (string si in selectedItems)
    string filePath = currDir + "\\" + si.ToString();
    string newFilePath = "\\\\Hades\\test2\\" + si.ToString();
    File.Move(filePath, newFilePath);


Setting the array to string gives me 'Source array type cannot be assigned
to destination array type' errors. Setting the array type to object as I
found in another post gives me 'The given path's format is not supported.'
and I notice that si.ToString() is equal to {text="filename.jpg"} instead of
just the filename.

What should I set it to to get this to work?

Also while I'm here I actually want to move these files to a folder on our
server. We are using Win2k for the workstations, I have the folder in
question shared and setup as a network place on the users machine, they have
full permissions over the folder. I'm assuming the path in the code snippit
above will work okay? Or do I have to start playing with tcp/ip stuff to
send it over the network?

Thanks in advance


Thu, 30 Dec 2004 05:57:50 GMT  
 listview and arrays
I figured out the array type, set it to ListViewItem - should have been
obvious... perils of coding when tired

However I have hit another strange problem. If I only select one file, it
works just fine, if I select more than one file it chokes.

To explain further when the file is selected it sets a picturebox on the
form to show the image. I hit this problem before and by using
pictureBox.Image.Dispose() to release the file before I do a rename or
delete I don't get any problems. Those parts are working very nicely.

It is obviously still working when I have only one image selected because it
moves it to the specified folder, however when I have more than one file
selected it gives me the usual exception error of 'can't access file because
it is being used by another process.' on the first file.

My new code is this:

    pictureBox.Image = null;



ListViewItem[] selectedItems = new
lvFileList.SelectedItems.CopyTo(selectedItems, 0);

foreach (ListViewItem si in selectedItems)
    string filePath = currDir + "\\" + si.Text;
    string newFilePath = "\\\\Hades\\test2\\" + si.Text;
    File.Move(filePath, newFilePath);


I have tried with the try catch statement where it is in the above snippit
and tried putting it in the foreach statement before the existing code. I've
also tried swapping the dispose and null lines round, removing the null
altogether and just in case taking out the try catch completely all the
while sticking the various variations in or out of the foreach loop. Nothing
makes any difference. Single file move works with all methods but multiple
file move still fails.

Thanks again


Thu, 30 Dec 2004 07:46:49 GMT  
 [ 2 post ] 

 Relevant Pages 

1. char array (array of array...) question

2. MD5 byte array to hex array

3. Implementing array of array

4. Array objects vs. square bracket [] arrays

5. Managed array of managed arrays of char

6. SOAP returning array of objects containing arrays

7. Novice: Pointing to arrays in array of structures

8. array index of smallest number in array?

9. Clean way to const-cast arrays of arrays?

10. use 1d array + macro or 2d array?

11. Storing an array in a temp array

12. Multiply and Add matrices with 2d array WITHOUT ARRAY INDEXING


Powered by phpBB® Forum Software