I apologize if this is a pretty simple fix, as I am new to C#. Here is a code snippet for monitoring a folder in Windows:
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = label1.Text;
watcher.NotifyFilter = NotifyFilters.LastWrite |
NotifyFilters.LastAccess |
NotifyFilters.FileName |
NotifyFilters.DirectoryName;
"
watch.Filter = "*.*";
watcher.Created += new FileSystemEventHandler(OnChanged(label4));
watcher.EnableRaisingEvents = true;
As you can see, while I'm monitoring a folder for files being "Created", for each file it will execute the method OnChanged
.
I have a label on my .net App, and I would like to pass that label text as a string variable into the OnChanged
method.
My question is how do I pass in a variable into the OnChanged method?
It appears whatever syntax I have tried, including the above syntax Visual Studio 2010 is not liking it.
The onChanged method looks like this:
public static void OnChanged(object source, FileSystemEventArgs e, String label4)
{
FileInfo file = new FileInfo(e.FullPath);
String fileName = file.Name;
String outputPath = label4.Text + file.Name;
}