I need to get selected items from a ListView and copy them to a folder.
I select folder with images and then show them in the ListView. Now I need to get all the selected items and copy them into another selected folder. Is there a way how to do it with better control then listview ?
I tried a few methods, but nothing works.
One approach:
int counter = 1;
foreach (ListViewItem item in listView1.SelectedItems)
{
var image = item.ImageList.Images[item.ImageKey]; //or imageIndex
using (MemoryStream memory = new MemoryStream())
{
using (FileStream fs = new FileStream($@"C:\temp\outputFileName_{counter}", FileMode.Create, FileAccess.ReadWrite))
{
image?.Save(memory, ImageFormat.Jpeg);
byte[] bytes = memory.ToArray();
fs.Write(bytes, 0, bytes.Length);
}
}
counter++;
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments