Sabari Prabu

Sabari Prabu

  • NA
  • 10
  • 2.6k

When i make listbox without extension i am facing exception

Apr 28 2015 9:17 AM
string folder = @"D:\\General";
string[] files = Directory.GetFiles(folder, "*.txt");
foreach (string i in files)
listBox1.Items.Add(Path.GetFileNameWithoutExtension(i.Trim()));


In the above code i given a local drive as input to listbox and filtered the .txt files.
when i click a radio button the output will be displayed in a text box. 
Then i made the items in listbox to appear only with name without extension.
When i make it, i face a exception in other codes below....


private void radiobtn_CheckedChanged(object sender, EventArgs e)
{
StreamReader objstream = new StreamReader(listBox1.Items[listBox1.SelectedIndex].ToString());-----here i face File Not Found exception  
Textbox1.Text = objstream.ReadToEnd();
}


Can anyone help please??




 

Answers (4)