-1
我試圖讓一個WPF應用程序顯示一個樹視圖與我的文件。我無法設法將driveinfo正確放入目錄信息中:treeview getdirectories得到錯誤
DirectoryInfo sdf = new DirectoryInfo(DriveInfo.GetDrives()[x].ToString());
foreach (DirectoryInfo z in sdf.GetDirectories()) //Run time error here
{ }
它給出了運行時錯誤。 下面是完整的代碼:
private void button1_Click(object sender, RoutedEventArgs e)
{
treeView1.Items.Clear();
for (int x = 0; x < DriveInfo.GetDrives().Length; x++)
{
TreeViewItem y = new TreeViewItem() { Header = DriveInfo.GetDrives()[x] };
treeView1.Items.Add(y);
comboBox1.Items.Add(DriveInfo.GetDrives()[x]);
DirectoryInfo sdf = new DirectoryInfo(DriveInfo.GetDrives()[x].ToString());
foreach (DirectoryInfo z in sdf.GetDirectories()) //Run time error here
{
TreeViewItem newmain = new TreeViewItem();
newmain.Header = z.Name;
newmain.Tag = z.FullName;
y.Items.Add(newmain);
}
}
的錯誤是:
IOException異常是未處理
「它給了我一個運行時錯誤」。什麼是例外? [你有什麼嘗試?](http://mattgemmell.com/2008/12/08/what-have-you-tried/) –