【发布时间】:2016-03-05 10:43:09
【问题描述】:
我想从列表框和文件夹中删除选定的文件。现在它只是从列表框中删除它。现在我希望它也从文件夹中删除。谢谢
private void tDeletebtn_Click(object sender, EventArgs e)
{
if (listBox1.SelectedIndex != -1)
listBox1.Items.RemoveAt(listBox1.SelectedIndex);
}
private void TeacherForm_Load(object sender, EventArgs e)
{
DirectoryInfo dinfo = new DirectoryInfo(@"data\\Teachers\\");
FileInfo[] Files = dinfo.GetFiles("*.xml");
foreach (FileInfo file in Files)
{
listBox1.Items.Add(file.Name);
}
}
【问题讨论】:
-
您的列表框项目中有文件路径吗?是全路径吗?
标签: c# xml listbox delete-file selectedindex