ListView 根据 文件路径 或 扩展名 显示系统文件图标
程序员文章站
2022-07-11 08:08:43
private void 获取文件button1_Click(object sender, EventArgs e) { folderBrowserDialog1.ShowDialog(); string path = folderBrowserDialog1.SelectedPath; listV ......
private void 获取文件button1_click(object sender, eventargs e)
{
folderbrowserdialog1.showdialog();
string path = folderbrowserdialog1.selectedpath;
folderbrowserdialog1.showdialog();
string path = folderbrowserdialog1.selectedpath;
listview1.view = view.list;
listview1.items.clear();
directoryinfo dir = new directoryinfo(path);
#region 递归遍历文件夹
foreach (directoryinfo dirfolder in dir.getdirectories())
{
foreach (directoryinfo dirfolder in dir.getdirectories())
{
listview1.smallimagelist = imagelist1;
listview1.items.add(dirfolder.name, 0);
}
#endregion
listview1.items.add(dirfolder.name, 0);
}
#endregion
#region 递归遍历文件;
foreach (fileinfo dirfile in dir.getfiles())
{
// listview1.items.add(dirfile.name, 1);
if (!imagelist1.images.keys.contains(dirfile.extension))
{
imagelist1.images.add(dirfile.extension,icon.extractassociatedicon(dirfile.fullname));
}
foreach (fileinfo dirfile in dir.getfiles())
{
// listview1.items.add(dirfile.name, 1);
if (!imagelist1.images.keys.contains(dirfile.extension))
{
imagelist1.images.add(dirfile.extension,icon.extractassociatedicon(dirfile.fullname));
}
listviewitem lvi = new listviewitem();
lvi.text = dirfile.name;
lvi.imageindex = imagelist1.images.keys.indexof(dirfile.extension);
listview1.items.add(lvi);
}
#endregion
}
lvi.text = dirfile.name;
lvi.imageindex = imagelist1.images.keys.indexof(dirfile.extension);
listview1.items.add(lvi);
}
#endregion
}
上一篇: 用PHP和ACCESS写聊天室(八)
下一篇: Winform文件上传