我的程序有问题。我想制作一个像 Window Explore 这样的应用程序,当我双击 ListView 中的一个项目时,它将在其中显示文件/文件夹部门。我使用此代码Path.GetFullPath(fileName)
查找所选项目名称的完整路径,但它始终返回我当前的项目路径。我无论如何都找不到解决它。有谁知道请帮帮我!非常感谢!这是我的代码:
private void listViewFolder_DoubleClick(object sender, EventArgs e)
{
if (this.listViewFolder.SelectedItems.Count == 1)
{
ListView temp = (ListView)sender;
string fileName = ((ListViewItem)temp.SelectedItems[0]).Text;
string filePath = Path.GetFullPath(fileName);
this.listViewFolder.Clear();
DirectoryInfo _nodeDirectory = new DirectoryInfo(filePath);
ListViewItem.ListViewSubItem[] _subFolder;
ListViewItem _item = null;
try
{
foreach (DirectoryInfo i in _nodeDirectory.GetDirectories())
{
_item = new ListViewItem(i.Name, 1);
_subFolder = new ListViewItem.ListViewSubItem[] { new ListViewItem.ListViewSubItem(_item, "Directory") };
this.listViewFolder.Items.Add(_item);
}
foreach (FileInfo file in _nodeDirectory.GetFiles())
{
_item = new ListViewItem(file.Name, 2);
_subFolder = new ListViewItem.ListViewSubItem[] { new ListViewItem.ListViewSubItem(_item, "File") };
}
}
catch (UnauthorizedAccessException ex)
{
MessageBox.Show("Folder Access denied", ex.Message, MessageBoxButtons.OK);
}
}
}