C#中怎么用listview显示指定路径下的文件和文件夹~ 比如我要显示D:\test\下的所有文件,最好也能显示图标~然后显示了之后还可以双击文件并且打开他~急求大神~本人初学C#不太懂网上写的什么Shell之类的~请大牛指教 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用什么shell,不就是目录遍历吗http://jlj84237485.blog.163.com/blog/static/34929460201010401434877/ List<ProgramInfo> ProInfo = new List<ProgramInfo>(); Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall", false); Microsoft.Win32.RegistryKey key2 = null; string softwareName, installLocation, IconPath; if (key != null)//判断对象存在 { foreach (string keyName in key.GetSubKeyNames())//遍历子项名称的字符串数组 { key2 = key.OpenSubKey(keyName, false);//遍历子项节点 if (key2 != null) { softwareName = key2.GetValue("DisplayName", "").ToString();//获取软件名 IconPath = key2.GetValue("DisplayIcon", "").ToString();//获取安装路径InstallLocation installLocation = key2.GetValue("InstallLocation", "").ToString(); if (!string.IsNullOrEmpty(installLocation)) { ProInfo.Add(new ProgramInfo() { ProName = softwareName, ProPath = installLocation, ProIconPath = IconPath }); } softwareName = ""; installLocation = ""; } key2 = null; } } for (int i = 0; i < ProInfo.Count; i++) { try { ProInfo[i].ProImage = System.Drawing.Icon.ExtractAssociatedIcon(ProInfo[i].ProIconPath); } catch { ProInfo[i].ProImage = null; } } int indexI = 0; imageList1.ImageSize = new Size(32, 32); imageList1.ColorDepth = ColorDepth.Depth32Bit; foreach (ProgramInfo i in ProInfo.ToArray()) { if (i.ProImage != null) { try { ListViewItem item = new ListViewItem(i.ProName); imageList1.Images.Add(i.ProImage.ToBitmap()); item.ImageIndex = indexI; item.BackColor = Color.Transparent; listView1.Items.Add(item); item.SubItems.Add(""); item.SubItems.Add(""); indexI++; } catch (Exception ex) { string e = ex.ToString(); } } } listView1.LargeImageList = imageList1; pictureBox1.Image = ProInfo[0].ProImage.ToBitmap(); class ProgramInfo { public string ProName; public string ProPath; public string ProIconPath; public Icon ProImage; }安装程序图标获取和显示private void BindDrives() { DriveInfo[] drvs = DriveInfo.GetDrives(); foreach (DriveInfo drv in drvs) { TreeNode root = new TreeNode(); root.Text = drv.Name; root.Tag = drv.RootDirectory.ToString(); // root.Nodes.Add(""); treeView1.Nodes.Add(root); if (Directory.Exists(drv.RootDirectory.ToString())) { DirectoryInfo dInfo = new DirectoryInfo(drv.RootDirectory.ToString()); FileSystemInfo[] files = dInfo.GetFileSystemInfos(); if (files.Length > 0) //有子节点,先添加一个空节点 { root.Nodes.Add("emptyNode", string.Empty); } } } } //展开节点,移除以前的空节点,加载子节点 private void treeView1_AfterExpand(object sender, TreeViewEventArgs e) { TreeNode parentNode = e.Node; // parentNode.Nodes.RemoveByKey("emptyNode");//移除空节点 parentNode.Nodes.Clear(); string path = parentNode.Tag.ToString(); if (Directory.Exists(path)) { DirectoryInfo dir = new DirectoryInfo(path); FileSystemInfo[] files = dir.GetFileSystemInfos(); foreach (FileSystemInfo f in files) { TreeNode node = new TreeNode(); node.Text = f.Name; node.Tag = f.FullName; parentNode.Nodes.Add(node); //加载子节点 if (Directory.Exists(node.Tag.ToString())) { DirectoryInfo subDir = new DirectoryInfo(node.Tag.ToString()); if (subDir.Attributes != (FileAttributes.System | FileAttributes.Hidden | FileAttributes.Directory)) { FileSystemInfo[] subFiles = null; try { subFiles = subDir.GetFileSystemInfos(); } catch { continue; } if (subFiles.Length > 0) //有子节点,先添加一个空节点 { node.Nodes.Add("emptyNode", string.Empty); } } } } } }目录树形结构显示。路径知道了打开文件就不用说了哈 用listview就是不行了么?这里只告诉方法不帮忙写代码的 arcmap C# 有啥资料推荐 我想在我的页面上显示报表,但是我不知道要怎样才能显示出Excel格式的报表,请各位大侠帮个忙,我要怎样才能才能在页面上显示? 急!人民币大小写转换 一个关于MessageBox的问题 请高手指教,有关在运行时取到变量的大小 sizeof如何取得引用型变量的所指向的内存区域的大小? 哪位大侠有各种数据库转换格式的方法和程序。 请问有没有什么关于C#中工厂模式的例子? 怎样在C#程序中开始另一个应用程序? 初学者在线求助:急!有没有现在有时间的asp.net的高手帮忙! C#中怎么结束一个已经触发了的事件 高德地图 怎么加上地形图
Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall", false);
Microsoft.Win32.RegistryKey key2 = null;
string softwareName, installLocation, IconPath;
if (key != null)//判断对象存在
{
foreach (string keyName in key.GetSubKeyNames())//遍历子项名称的字符串数组
{
key2 = key.OpenSubKey(keyName, false);//遍历子项节点 if (key2 != null)
{
softwareName = key2.GetValue("DisplayName", "").ToString();//获取软件名
IconPath = key2.GetValue("DisplayIcon", "").ToString();//获取安装路径InstallLocation
installLocation = key2.GetValue("InstallLocation", "").ToString();
if (!string.IsNullOrEmpty(installLocation))
{
ProInfo.Add(new ProgramInfo()
{
ProName = softwareName,
ProPath = installLocation,
ProIconPath = IconPath
});
}
softwareName = "";
installLocation = "";
}
key2 = null;
}
}
for (int i = 0; i < ProInfo.Count; i++)
{
try
{
ProInfo[i].ProImage = System.Drawing.Icon.ExtractAssociatedIcon(ProInfo[i].ProIconPath);
}
catch { ProInfo[i].ProImage = null; }
}
int indexI = 0;
imageList1.ImageSize = new Size(32, 32);
imageList1.ColorDepth = ColorDepth.Depth32Bit;
foreach (ProgramInfo i in ProInfo.ToArray())
{
if (i.ProImage != null)
{
try
{
ListViewItem item = new ListViewItem(i.ProName);
imageList1.Images.Add(i.ProImage.ToBitmap());
item.ImageIndex = indexI;
item.BackColor = Color.Transparent;
listView1.Items.Add(item);
item.SubItems.Add("");
item.SubItems.Add("");
indexI++;
}
catch (Exception ex) { string e = ex.ToString(); }
}
}
listView1.LargeImageList = imageList1;
pictureBox1.Image = ProInfo[0].ProImage.ToBitmap();
class ProgramInfo
{
public string ProName;
public string ProPath;
public string ProIconPath;
public Icon ProImage;
}安装程序图标获取和显示
private void BindDrives()
{
DriveInfo[] drvs = DriveInfo.GetDrives();
foreach (DriveInfo drv in drvs)
{
TreeNode root = new TreeNode();
root.Text = drv.Name;
root.Tag = drv.RootDirectory.ToString();
// root.Nodes.Add("");
treeView1.Nodes.Add(root);
if (Directory.Exists(drv.RootDirectory.ToString()))
{
DirectoryInfo dInfo = new DirectoryInfo(drv.RootDirectory.ToString()); FileSystemInfo[] files = dInfo.GetFileSystemInfos();
if (files.Length > 0) //有子节点,先添加一个空节点
{
root.Nodes.Add("emptyNode", string.Empty);
}
}
}
} //展开节点,移除以前的空节点,加载子节点
private void treeView1_AfterExpand(object sender, TreeViewEventArgs e)
{
TreeNode parentNode = e.Node;
// parentNode.Nodes.RemoveByKey("emptyNode");//移除空节点
parentNode.Nodes.Clear();
string path = parentNode.Tag.ToString(); if (Directory.Exists(path))
{
DirectoryInfo dir = new DirectoryInfo(path); FileSystemInfo[] files = dir.GetFileSystemInfos();
foreach (FileSystemInfo f in files)
{
TreeNode node = new TreeNode();
node.Text = f.Name;
node.Tag = f.FullName;
parentNode.Nodes.Add(node); //加载子节点 if (Directory.Exists(node.Tag.ToString()))
{
DirectoryInfo subDir = new DirectoryInfo(node.Tag.ToString());
if (subDir.Attributes != (FileAttributes.System | FileAttributes.Hidden | FileAttributes.Directory))
{
FileSystemInfo[] subFiles = null;
try
{
subFiles = subDir.GetFileSystemInfos();
}
catch { continue; }
if (subFiles.Length > 0) //有子节点,先添加一个空节点
{
node.Nodes.Add("emptyNode", string.Empty);
}
}
}
} }
}目录树形结构显示。路径知道了打开文件就不用说了哈
不帮忙写代码的