I have listBox1 and listBox2 which are loaded with some files from a directory. Initially when I load the form I disabled buttons for the listBox1 and listBox2.
When there is no file in the directory I want to disable the button1 for listBox1 and button2 listBox2.
But I want to enable the buttons of the corresponding listBox1 and listBox2 if there is a single file in the directory and if there is any change in the files.
How do i perform this using FileSystemWatcher ??? I need some idea to perform this.
private void PopulateListBox(ListBox lsb, string Folder, string FileType)
{
DirectoryInfo dinfo = new DirectoryInfo(Folder);
FileInfo[] Files = dinfo.GetFiles(FileType);
foreach (FileInfo file in Files)
{
lsb.Items.Add(file);
}
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
FileInfo file = (FileInfo)listBox1.SelectedItem;
string path = file.FullName;
DisplayFile(path);
}
private void button1_Click(object sender, EventArgs e)
{
}
private void fileSystemWatcher1_Changed(object sender, FileSystemEventArgs e)
{
}
I have initialized a method here, from here how can i proceed???
public void filesystemwatcher()
{
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = @"C:\LoadFiles\";
}
You can use a BindingList with the FileSystemWatcher: