Creating File Watcher

I had created a file watcher, using windows services in C#.

This is use to monitor all the events in a particular folder.

You can install it in yours frndz PC and see what he dose........

I had attached the application & also walkthrough....

plz reffer it for help.....


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.IO;


namespace filewatcher
{
public partial class Service1 : ServiceBase
{
public Service1()
{
InitializeComponent();
}

/* creating an object */
StreamWriter str = new StreamWriter("D:\\watcher.txt", true);
FileSystemWatcher fsw = new FileSystemWatcher ("D:\\filewatcher");

protected override void OnStart(string[] args)
{
fsw.Filter="*.*";
fsw.EnableRaisingEvents = true;
fsw.Created += new FileSystemEventHandler(fsw_Created);
fsw.Deleted += new FileSystemEventHandler(fsw_Deleted);
fsw.Renamed += new RenamedEventHandler(fsw_Renamed);
}

/* code for get the event of rename */
void fsw_Renamed(Object sender, RenamedEventArgs e)
{
str.WriteLine(e.OldName+" has been renamed to "+e.Name);
str.Flush();
}

/* code for get the event of delete */
void fsw_Deleted(Object sender, FileSystemEventArgs e)
{
str.WriteLine(Environment.UserName+" has been deleted "+e.Name+" from "+fsw.Path);
str.Flush();
}

/* code for get the event of create */

void fsw_Created(Object sender, FileSystemEventArgs e)
{
str.WriteLine("A new file " + e.Name + " has been created in "+fsw.Path);
str.Flush();
}

/* code to stop the file watcher */

protected override void OnStop()
{
str.WriteLine("service stoped on " + DateTime.Now.ToString());
str.Close();

}
}
}


Attachments

  • How to create our own File Watcher (28309-81232-How to create our own File Watcher.doc)
  • Project of File Watcher (28309-81236-filewatcher.rar)
  • Comments

    No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: