如何纠正错误“非法形式的路径”
问题描述:
我正在使用树视图,我希望能够在单击该文件夹中的文件后获取文件夹中的所有文件。
我正在使用此代码:
I am using a treeview, and I want to be able to get all the files inside a folder after I click a file inside that folder.
I am using this code:
//I am getting path has an ilegal form in the next line
//I also tried this statement inside the foreach, but with no luck
(Path.GetFullPath(Path.GetFileName(trwFileExplorer.SelectedNode.Name))))
//This was the other thing I tried
path.Text = Path.GetDirectoryName(trwFileExplorer.SelectedNode.Name);
//and I am getting the same error here inside the foreach
foreach (string file in Directory.GetFiles(path.Text))
{
media = player.newMedia(Path.GetFullPath(Path.GetFileName(file.ToString())));
playlist.appendItem(media);
//path.Text = Path.GetFullPath(Path.GetFileName(file.ToString()));
}
如何解决这个问题?
谢谢!
How can I fix this?
Thanks!
答
调试并检查运行时trwFileExplorer.SelectedNode.Name
的值。您确定要使用treeview Name属性吗?它应该是文本
或值
,具体取决于您如何绑定数据和您的要求。
Debug and check what is the value you get astrwFileExplorer.SelectedNode.Name
in runtime. Are you sure that you want treeview Name property? it should beText
orValue
depending on how you bind data and your requirements.