C
C#2mo 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
LPeter19972mo ago
You are already using the right tool for it, FileSystemWatcher, what would you like to improve?
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
CrosRoad95
CrosRoad95OP2mo 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 User2mo ago
Message Not Public
Sign In & Join Server To View
CrosRoad95
CrosRoad95OP2mo ago
project where .csproj file is
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
CrosRoad95
CrosRoad95OP2mo ago
Because next to this file is my "file.txt" i want to watch using file watcher
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
CrosRoad95
CrosRoad95OP2mo ago
this is not config file, rather script
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
CrosRoad95
CrosRoad95OP2mo ago
But i want at runtime know when file changed And this is not config file... i can't use appsettings
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
CrosRoad95
CrosRoad95OP2mo ago
file structure looks like this
No description
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
CrosRoad95
CrosRoad95OP2mo ago
When i run project it run it in different folder than project
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
CrosRoad95
CrosRoad95OP2mo ago
yes
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
sibber
sibber2mo 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