0
我的程序有問題。我想創建一個像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);
}
}
}