hey, i have my streamreader code, but im running it in a filesystem watcher program,
once a certain file is seen, then read other files in the folder
so i basically have the filesystem watcher set up to wait for this certain file. then i know the reader tries to find a file but it cant. I think the problem must be the reader needing the folder directory that the filesystemwatcher is looking in, but i have no idea how.
for example, here is the code i have, how do i modify it to read files in the folder specified in "DestDir"
namespace ConsoleApplication1
{
class process
{
private static string myString = string.Empty;
static void Main(string[] args)
{
Run();
}
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
public static void Run()
{
string[] args = System.Environment.GetCommandLineArgs();
// Create a new FileSystemWatcher and set its properties.
FileSystemWatcher watcher = new FileSystemWatcher();
string test1 = System.Configuration.ConfigurationSettings.AppSettings["DestDir"];
watcher.Path = test1;//args[1];
/* Watch for changes in LastAccess and LastWrite times, and
the renaming of files or directories. */
watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
| NotifyFilters.FileName | NotifyFilters.DirectoryName;
// Only watch text files.
watcher.Filter = "TransferComplete.*";
// Add event handlers.
//watcher.Changed += new FileSystemEventHandler(OnChanged);
watcher.Created += new FileSystemEventHandler(OnChanged);
//watcher.Deleted += new FileSystemEventHandler(OnChanged);
//watcher.Renamed += new RenamedEventHandler(OnRenamed);
// Begin watching.
watcher.EnableRaisingEvents = true;
// Wait for the user to quit the program.lol
Console.WriteLine("Press \'q\' to quit the sample.");
while (Console.Read() != 'q') ;
}
// Define the event handlers.
private static void OnChanged(object source, FileSystemEventArgs e)
{
try
{
// Create an instance of StreamReader to read from a file.
// The using statement also closes the StreamReader.
using (StreamReader sr = new StreamReader("TestFile.txt"))
{
String line;
// Read and display lines from the file until the end of
// the file is reached.
while ((line = sr.ReadLine()) != null)
{
Console.WriteLine(line);
}
}
}
catch (Exception d)
{
// Let the user know what went wrong.
Console.WriteLine("The file could not be read:");
Console.WriteLine(d.Message);
}
}
}
}