Abdu Abdul

Abdu Abdul

  • 1.3k
  • 409
  • 15.1k

download multiple images into a folder from listview

Mar 18 2021 10:22 PM
I am displaying multiple images in listview from database and is working fine, the problem am having is when ever I wan't to download multiple selected images into any folder on my desktop computer, only one image is downloaded not multiple selected images : check my codes
  1. FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();  
  2.   
  3. if (folderBrowserDialog.ShowDialog() == DialogResult.OK) {  
  4.   if (listView1.Items.Count > 0) {  
  5.     listView1.FocusedItem = listView1.Items[0];  
  6.     listView1.Items[0].Selected = true;  
  7.     listView1.Select();  
  8.     SqlCommand cmd = new SqlCommand("SELECT Name,Data FROM [gallery]", connect);  
  9.     cmd.CommandType = CommandType.Text;  
  10.     connect.Open();  
  11.     SqlDataReader sdr = cmd.ExecuteReader();  
  12.     if (sdr.Read()) {  
  13.       byte[] bytes = (byte[]) sdr["Data"];  
  14.       string fileName = sdr["Name"].ToString();  
  15.       string path = Path.Combine(folderBrowserDialog.SelectedPath, fileName);  
  16.       File.WriteAllBytes(path, bytes);  
  17.     }  
  18.     connect.Close();  
  19.   }  
  20. }

Answers (3)