Displays the selected image in listview and shows simple instances of filename path and type
- 2020-07-21 07:22:16
- OfStack
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
listView1.Items.Clear();
string[] files = openFileDialog1.FileNames; // define 1 An array of the selected files
string[] fileinfo = new string[3]; // define 1 Three arrays, used to store file information
for (int i = 0; i < files.Length; i++) // Iterate through an array of files
{
string path = files[i].ToString(); // Get file path
// Intercepting file name
string fileName = path.Substring(path.LastIndexOf("\\") + 1, path.Length - 1 - path.LastIndexOf("\\"));
// Intercepting file type
string fileType = fileName.Substring(fileName.LastIndexOf(".") + 1, fileName.Length - 1 - fileName.LastIndexOf("."));
fileinfo[0] = fileName;
fileinfo[1] = path;
fileinfo[2] = fileType;
ListViewItem lvi = new ListViewItem(fileinfo);
listView1.Items.Add(lvi);
}
}
Note: ListView1, View attribute Details
OpenFileDialog1,Multiselect attribute true