C
C#4w ago
CrosRoad95

FileWatcher for project folder

string outputDirectory = AppDomain.CurrentDomain.BaseDirectory;
string projectDirectory = Directory.GetParent(outputDirectory).Parent.Parent.Parent.FullName; // Navigate to the project folder

this.watcher = new FileSystemWatcher();
this.watcher.Path = projectDirectory;
string outputDirectory = AppDomain.CurrentDomain.BaseDirectory;
string projectDirectory = Directory.GetParent(outputDirectory).Parent.Parent.Parent.FullName; // Navigate to the project folder

this.watcher = new FileSystemWatcher();
this.watcher.Path = projectDirectory;
anyone have better idea how to listen for changes in project folder? i have text file in this folder and i want to listen for changes
19 Replies
LPeter1997
LPeter19974w ago
You are already using the right tool for it, FileSystemWatcher, what would you like to improve?
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
CrosRoad95
CrosRoad954w ago
i just posted minimal code, i'm attaching events. i want to refactor this: string outputDirectory = AppDomain.CurrentDomain.BaseDirectory; string projectDirectory = Directory.GetParent(outputDirectory).Parent.Parent.Parent.FullName; // Navigate to the project folder Is there any magic variable like "ProjectPath"?
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
CrosRoad95
CrosRoad954w ago
project where .csproj file is
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
CrosRoad95
CrosRoad954w ago
Because next to this file is my "file.txt" i want to watch using file watcher
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
CrosRoad95
CrosRoad954w ago
this is not config file, rather script
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
CrosRoad95
CrosRoad954w ago
But i want at runtime know when file changed And this is not config file... i can't use appsettings
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
CrosRoad95
CrosRoad954w ago
file structure looks like this
No description
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
CrosRoad95
CrosRoad954w ago
When i run project it run it in different folder than project
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
CrosRoad95
CrosRoad954w ago
yes
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
sibber
sibber4w ago
you dont typically ship the source code with the app just put the file in the output directory and read from AppContext.BaseDirectory
Want results from more Discord servers?
Add your server