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