Click here to Skip to main content
15,896,552 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have created a program for filewatcher but not able to understand it in console application though i understood it in window application.

C#
namespace fsw_watcher
{
    class Program
    {
        static void Main(string[] args)
        {
            FileSystemWatcher fsw = new FileSystemWatcher (Environment.GetEnvironmentVariable("USERPROFILE"));
            fsw.IncludeSubdirectories = true;
            fsw.NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite;

            fsw.Created += new FileSystemEventHandler(fsw_created);
            fsw.Deleted += new FileSystemEventHandler(fsw_deleted);
            fsw.Renamed += new RenamedEventHandler(fsw_Renamed);
            fsw.Changed += new FileSystemEventHandler(fsw_Changed);
            fsw.EnableRaisingEvents = true;
            Console.WriteLine("Press a key to end the program.");
            Console.ReadKey();
        }

        static void fsw_created(object sender, FileSystemEventArgs e)
        {
            Console.WriteLine("created"+ e.FullPath);
        }
        static void fsw_deleted(object sender, FileSystemEventArgs e)
        {
            Console.WriteLine("deleted" + e.FullPath);
        }
        static void fsw_Changed(object sender, FileSystemEventArgs e)
        {
            Console.WriteLine(e.ChangeType + ": " + e.FullPath);
        }


        static void fsw_Renamed(object sender, RenamedEventArgs e)
        {
            Console.WriteLine(e.ChangeType + " from " + e.OldFullPath + " to " + e.Name);
        }
    }
}


in window form i was able to give path and could monitor there but here i am not able to locate where to give path.
So if anybody could help me in this .
thanks
regards
Posted
Comments
Sergey Alexandrovich Kryukov 17-Nov-11 23:41pm    
A question makes no sense at all, because "where to give path" totally depends on what you want to achieve. There is no essential difference between console application and anything else.

--SA
shivani 2013 18-Nov-11 4:32am    
i want to say that filewatcher is used to monitor the files for a particular path we give ....here where i need to

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900