Search this blog

You can search for all the topics in our blog using our google custom search now.

Search the blog

Loading

Monday, August 16, 2010

Monitoring File System

Hi,
I have done a simple tutorial on monitoring file systems. Please watch the video tutorials which is split in three parts:

Ads By Google




Part -- 1 :-



Part -- 2 :-



Part -- 3 :-



The code for the tutorial is as follows:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace MonitorFilesExample
{
    class Program
    {
        static void Main(string[] args)
        {
            Run();

        }

        public static void Run()
        {
            FileSystemWatcher Watcher = new FileSystemWatcher(Environment.GetEnvironmentVariable("USERPROFILE"));
            Watcher.Path = @"C:\My stuff\Work Stuff\Vship";
            Watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
            Watcher.Filter = "*.txt";

            //Add event handlers for all the events
            Watcher.Changed += new FileSystemEventHandler(Watcher_Changed);
            Watcher.Renamed += new RenamedEventHandler(Watcher_Renamed);
            Watcher.Deleted += new FileSystemEventHandler(Watcher_Deleted);

            Watcher.EnableRaisingEvents = true;
            Console.ReadKey();
          
        }

        static void Watcher_Deleted(object sender, FileSystemEventArgs e)
        {
            Console.WriteLine("File : " + e.FullPath + " Change Type is : " + e.ChangeType);
        }

        static void Watcher_Renamed(object sender, RenamedEventArgs e)
        {
            Console.WriteLine("File : " + e.FullPath + " Change Type is : " + e.ChangeType);
        }

        static void Watcher_Changed(object sender, FileSystemEventArgs e)
        {
            Console.WriteLine("File : "+e.FullPath+ " Change Type is : "+ e.ChangeType);
        }
    }
}

Regards
Sameer Shaik

Tags: Microsoft MCTS exam, Learn, Tutorials, Free C#, Free Videos, Microsoft Dot Net Jobs,Microsoft Dot Net Jobs Interview, Free Training and Preparation, Jobs MCTS specialization, visual studio.net, study guide, sample questions, Exam Prep, Exam Practice Test

No comments:

Post a Comment