473,387 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

monitoring foler for file modification

Hi all,

Can someone point me in the direction on this one, resources or examples.
I am writing a Windows Service to monitor a folder. When I file is modified
within the folder or any subfolders it should write the name of the file to
a xml file.
Then at a specifed time all the files in the xml quene will be backed up on
a network share.

How would I go about monitoring a folder and all subfolders and detect when
a file within has been modifed?
Thanks,
Ron Vecchi
Nov 15 '05 #1
3 4124
Ron,
Have you looked at the System.IO.FileSystemWatcher class?

It allows you to watch for changes in a specified directory, and its
subdirectories.

Hope this helps
Jay

"Ron Vecchi" <rv*****@xilehdvecchi.com> wrote in message
news:OI**************@TK2MSFTNGP11.phx.gbl...
Hi all,

Can someone point me in the direction on this one, resources or examples.
I am writing a Windows Service to monitor a folder. When I file is modified within the folder or any subfolders it should write the name of the file to a xml file.
Then at a specifed time all the files in the xml quene will be backed up on a network share.

How would I go about monitoring a folder and all subfolders and detect when a file within has been modifed?
Thanks,
Ron Vecchi

Nov 15 '05 #2
Check out the FileSystemWatcher documentation in the .NET
framework SDK reference. It has an example that claims to do
what you want. I'm attaching the C# example from that page
below.

Andrew Queisser

***********************
public class Watcher
{

public static void Main()
{

string[] args = System.Environment.GetCommandLineArgs();

// If a directory is not specified, exit program.
if(args.Length != 2)
{
// Display the proper way to call the program.
Console.WriteLine("Usage: Watcher.exe (directory)");
return;
}

// Create a new FileSystemWatcher and set its properties.
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = args[1];
/* Watch for changes in LastAccess and LastWrite times, and
the renaming of files or directories. */
watcher.NotifyFilter = NotifyFilters.LastAccess |
NotifyFilters.LastWrite
| NotifyFilters.FileName | NotifyFilters.DirectoryName;
// Only watch text files.
watcher.Filter = "*.txt";

// Add event handlers.
watcher.Changed += new FileSystemEventHandler(OnChanged);
watcher.Created += new FileSystemEventHandler(OnChanged);
watcher.Deleted += new FileSystemEventHandler(OnChanged);
watcher.Renamed += new RenamedEventHandler(OnRenamed);

// Begin watching.
watcher.EnableRaisingEvents = true;

// Wait for the user to quit the program.
Console.WriteLine("Press \'q\' to quit the sample.");
while(Console.Read()!='q');
}

// Define the event handlers.
private static void OnChanged(object source, FileSystemEventArgs e)
{
// Specify what is done when a file is changed, created, or deleted.
Console.WriteLine("File: " + e.FullPath + " " + e.ChangeType);
}

private static void OnRenamed(object source, RenamedEventArgs e)
{
// Specify what is done when a file is renamed.
Console.WriteLine("File: {0} renamed to {1}", e.OldFullPath,
e.FullPath);
}
}


"Ron Vecchi" <rv*****@xilehdvecchi.com> wrote in message
news:OI**************@TK2MSFTNGP11.phx.gbl...
Hi all,

Can someone point me in the direction on this one, resources or examples.
I am writing a Windows Service to monitor a folder. When I file is modified within the folder or any subfolders it should write the name of the file to a xml file.
Then at a specifed time all the files in the xml quene will be backed up on a network share.

How would I go about monitoring a folder and all subfolders and detect when a file within has been modifed?
Thanks,
Ron Vecchi

Nov 15 '05 #3
Thanks, this got me going

Ron

"Ron Vecchi" <rv*****@xilehdvecchi.com> wrote in message
news:OI**************@TK2MSFTNGP11.phx.gbl...
Hi all,

Can someone point me in the direction on this one, resources or examples.
I am writing a Windows Service to monitor a folder. When I file is modified within the folder or any subfolders it should write the name of the file to a xml file.
Then at a specifed time all the files in the xml quene will be backed up on a network share.

How would I go about monitoring a folder and all subfolders and detect when a file within has been modifed?
Thanks,
Ron Vecchi

Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ron | last post by:
I am trying to run asp.net pages. The server is accessed via http://sitename/username I have verified it is using port 80 and aspx extensions are configured. But when I run and asp.net page I...
4
by: johnm | last post by:
Hello, We currently are running a CRM application that uses DB/2 7.2 for the data repository. We will be upgrading to 8.2 later this year....maybe....time and resources permitting. The...
0
by: Jeff Reed | last post by:
I am experiencing the the problem outlined the below. Unfortunately, I am using WinXP and I not sure if I can apply the solution due to lack of security control Any feed back would be apreciated ...
1
by: Edward Yang | last post by:
I setup web.config with impersonation="true". On our local server the project works great. I did the same procedures on our staging server, but it failed with an impossible error: Server Error in...
0
by: Ron Simpson | last post by:
I am trying to run asp.net pages. The server is accessed via http://sitename/username I have verified it is using port 80 and aspx extensions are configured. But when I run and asp.net page I...
9
by: Tim D | last post by:
Hi, I originally posted this as a reply to a rather old thread in dotnet.framework.general and didn't get any response. I thought it might be more relevant here; anyone got any ideas? My...
5
by: Joe | last post by:
I'm getting the following error when trying to call a page on a secure server. I'm not doing any impersonations or file access of any kind. The page is using PayPal and I'm wondering if PayPal has...
3
by: rohit | last post by:
hi i want to detect all file change operations(rename,delete,create....) on ALL THE DRIVES of the hard disk using the method ReadDirectoryChanges API , i.e program no. 3 in the webpage...
0
by: Vinod Sadanandan | last post by:
STANDBY DATABASE MONITORING & PROTECION MODES (9iR2) This document is written for understanding and monitoring standby database configured with diffrent protection modes . MAXIMUM PROTECTION ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.