Search code examples
c#pathruntimefilesystemwatcher

File System Watcher has a user determined path?


How do you get the File System watcher to watch a path selected at run time e.g. the user can enter C:\Users\User\Desktop\

I have tried using a text box and a button which on click sets the path

    fileWatcher.Path = Convert.ToString(txtFileWatcherPath);

This builds and runs but any path entered crashes the program (once the button is clicked)

Please note at this early stage am not concerned with error handling.


Solution

  • if txtFileWatcherPath is a textbox, then use txtFileWatcherPath.Text instead of Convert.ToString