Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2012-03-29
3
Medium Priority
?
557 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 20

Accepted Solution

by:
BuggyCoder earned 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Suggested Courses

610 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