Can anyone tell me why this code doesn't work?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace Assignment___Tekst_čitač
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
DriveInfo[] drives = DriveInfo.GetDrives();
for (int i = 0; i <= drives.Length - 1; i++)
{
comboBox1.Items.Add(drives[i].Name);
comboBox1.SelectedIndex = -1;
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
treeView1.Nodes.Clear();
DirectoryInfo path = new DirectoryInfo(comboBox1.SelectedItem.ToString());
try
{
foreach (DirectoryInfo dir in path.GetDirectories())
{
TreeNode node = treeView1.Nodes.Add(dir.Name);
node.Nodes.Add(" ");
}
foreach (FileInfo file in path.GetFiles())
{
if (file.Extension.ToLower() == ".txt")
{
TreeNode node = treeView1.Nodes.Add(file.Name);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void treeView1_BeforeExpand(object sender, TreeViewCancelEventArgs e)
{
try
{
TreeNode courentNode = e.Node;
DirectoryInfo folderPaht = new DirectoryInfo(comboBox1.SelectedItem + courentNode.FullPath);
foreach (DirectoryInfo dir in folderPaht.GetDirectories())
{
string fileName = dir.Name;
TreeNode node = courentNode.Nodes.Add(fileName);
node.Nodes.Add(" ");
}
foreach (FileInfo file in folderPaht.GetFiles())
{
string ext = file.Extension;
if (ext.ToLower() == ".txt")
{
TreeNode newNode = courentNode.Nodes.Add(file.Name);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void button1_Click(object sender, EventArgs e)
{
string fulPath = comboBox1.SelectedItem + treeView1.SelectedNode.FullPath;
if (fulPath.ToLower().EndsWith(".txt"))
{
StreamReader read = new StreamReader(fulPath);
richTextBox1.Text = read.ReadToEnd();
read.Close();
}
else
MessageBox.Show("");
}
}
}