FileSystemWatcher example

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Does anyone have an example of how to use this object

Basically, I want to check for changes in a directory automatically and if their are changes to it (ie FTP) then I want the system to auto upload to the database

But I need an example to get starte

Thank

Adam
 
Here's an example that fires an event whenever a file is added to the
specified folder.

// folder to watch
FileSystemWatcher theWatcher = new FileSystemWatcher(@"e:\WatchThisFolder");

// type of change to watch for
theWatcher.NotifyFilter = NotifyFilters.FileName;

// delegate to handle the event
theWatcher.Created += new FileSystemEventHandler(this.OnFolderChanged);

// begin watching
theWatcher.EnableRaisingEvents = true;

// delegate method to handle the Created event of the FSW
// just output the name of the file to the debugger
void OnFolderChanged(object o, FileSystemEventArgs e)
{
System.Diagnostics.Debug.WriteLine(e.Name);
}

Check out
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemiofilesystemwatcherclasstopic.asp for addional information.

hth

-Joel
--------------------
Thread-Topic: FileSystemWatcher example
thread-index: AcQcr7+ifwN/E1cKT1Ca9CVI1YH46A==
X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
From: "=?Utf-8?B?QWRhbUQ=?=" <[email protected]>
Subject: FileSystemWatcher example
Date: Wed, 7 Apr 2004 07:51:03 -0700
Lines: 10
Message-ID: <[email protected]>
MIME-Version: 1.0
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
Newsgroups: microsoft.public.dotnet.languages.csharp
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:235887
NNTP-Posting-Host: tk2msftcmty1.phx.gbl 10.40.1.180
X-Tomcat-NG: microsoft.public.dotnet.languages.csharp

Does anyone have an example of how to use this object.

Basically, I want to check for changes in a directory automatically and if
their are changes to it (ie FTP) then I want the system to auto upload to
the database.

But I need an example to get started

Thanks

AdamD
 
Back
Top