Click here to Skip to main content
15,900,511 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi..all

I want to create an Application using C# (Visual Studio 2008),My app process is expected to monitor the copy-paste file process that is doing by the current logged user.

But the problem is that,I give only one path to FileSystemWatcher object. I monitor my all drive. But it can't posible to handle to me.In my machine have multiple drive Ex : c:\, D:\, etc...
So how can i give to FileSystemWatcher.Path ???

I override onstart mathod on my services start.Code is under

protected override void OnStart(string[] args)
{
	FileSystemWatcher.path = "C:\\"
}


Any solution would get my great appreciation.
Thanks..
Posted
Updated 8-Aug-10 21:56pm
v2

You can simply use a FileSystemWatcher for each drive. Simply create a list or vector and for each drive you add a FileSystemWatcher.

Good luck!
 
Share this answer
 
Answer from other guys, It helpful to other coder.

C#
protected override void OnStart(string[] args)
{

string[] drives = Environment.GetLogicalDrives();

_watchers = new FileSystemWatcher[drivers.Length];

int i = 0;

foreach (string strDrive in drives)

{

FileSystemWatcher _watcher = new FileSystemWatcher();

_watcher.Path = strDrive;

_watcher.Changed += new FileSystemEventHandler(FolderWatcherTest_Changed);

_watcher.Created += new FileSystemEventHandler(FolderWatcherTest_Created);

_watcher.Deleted += new FileSystemEventHandler(FolderWatcherTest_Deleted);

_watcher.Renamed += new RenamedEventHandler(FolderWatcherTest_Renamed);

_watchres[i] = watcher;

//Begin watching.
watcher.EnableRaisingEvents = true;

i++;

}

}
 
Share this answer
 
v3

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