Solved

How to capture FileSystemWatcher events  for the watch directory itself using C#

Posted on 2012-03-29
3
530 Views
Last Modified: 2012-03-29
How can I capture FileSystem events for the watch directory( not the subdirectory) if I delete/rename  the watch folder named "C:\FileWatcher".

 ie, my watch directory is FileWatcher, if user delete FileWatcher, I need to get the delete events for the directory FileWatcher, similarly rename also. Is there any way to do this in C#?

Please help.
0
Comment
Question by:HPFE455
  • 2
3 Comments
 
LVL 20

Accepted Solution

by:
BuggyCoder earned 500 total points
ID: 37782119
here is an extension to it, that even tells you if the folder being watched is deleted:-

http://www.codeproject.com/Articles/15656/Advanced-FileSystemWatcher

Here is another interesting extension (not related to your question, but still interesting, i am sure you would like it):_
http://www.codeproject.com/Articles/102493/Enhanced-FileSystemWatcher
0
 

Author Comment

by:HPFE455
ID: 37782527
Thanks  BuggyCoder, I think your solution is apt to my requirement, I am trying to implement the timer in my code

System.Timers.Timer myTimer = new System.Timers.Timer();
myTimer.Elapsed += new ElapsedEventHandler(OnElapsedTimer);
myTimer.Interval = 5000;
myTimer.Enabled = true;

private static void OnDeleted(object source, RenamedEventArgs e)   
{
Console.WriteLine("File: {0} renamed to {1}", e.OldFullPath, e.FullPath);

}

 private static void OnElapsedTimer(object source, ElapsedEventArgs e)
    {
         path = "C:\MyMusic"
         if (!Directory.Exists(path))         
       {
        // Here I need invoke OnDeleted File Watcher method if the directory does not exist

       }
}

Open in new window


How can I invoke OnDeleted  method, if watch directory does not exist?
0
 

Author Closing Comment

by:HPFE455
ID: 37783955
Thanks for providing me the solution
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ConsoleSql 1 34
Search by two fields at the same time using c# radio button 5 39
In WPF / C# binding a local database in code behind 1 24
Run time Error 4 35
Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now