473,320 Members | 1,887 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,320 software developers and data experts.

Monitoring a Directory

Hi,

I need to monitor a directory for files. When a file is moved into this
direcotry I need some sort of event to be called and the file will then
be picked up.
I have done this type of thing using MFC, and used FindFirstFile, making
a call to that ever x milliseconds. I am just wondering if .NET has
something different to offer for problems like this ?

Regards,

Steven

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #1
4 1173
Steven,

Please have a look at the FileSystemWatcher class in the .NET
Framework. Also do a search about it in this newsgroup and read up
on some of the issues that people have run into, to save yourself some
time =)

HTH,

//Andreas

--
ANDREAS HÅKANSSON
STUDENT OF SOFTWARE ENGINEERING
andreas (at) selfinflicted.org
"Steven Blair" <st**********@btinternet.com> wrote in message news:uh**************@TK2MSFTNGP12.phx.gbl...
Hi,

I need to monitor a directory for files. When a file is moved into this
direcotry I need some sort of event to be called and the file will then
be picked up.
I have done this type of thing using MFC, and used FindFirstFile, making
a call to that ever x milliseconds. I am just wondering if .NET has
something different to offer for problems like this ?

Regards,

Steven

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #2
Steven Blair <st**********@btinternet.com> wrote:
I need to monitor a directory for files. When a file is moved into this
direcotry I need some sort of event to be called and the file will then
be picked up.
I have done this type of thing using MFC, and used FindFirstFile, making
a call to that ever x milliseconds. I am just wondering if .NET has
something different to offer for problems like this ?


Well, there's FileSystemWatcher. However, you should note that it's not
available on all platforms, and I've read various reports about it not
working terribly reliably :(

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3
If by "picking up" the file, you mean you will be removing it from the
directory (that is, any file in the directory is in a queue to be processed)
then I think I would use a Timer (either the System.Timers.Timer class or
the System.Threading.Timer class) set it for a few milliseconds (or 1/10 of
a second, whatever works for your app) and then use the
System.IO.Directory.GetFiles function to get an array of Filename in the
directory, or use the System.IO.DirectoryInfo class, and the GetFiles method
to get an enumertor of FileInfo objects, one for every file in the
directory.
--
Mike Mayer, C# MVP
mi**@mag37.com
http://www.mag37.com/csharp/
"Steven Blair" <st**********@btinternet.com> wrote in message
news:uh**************@TK2MSFTNGP12.phx.gbl...
Hi,

I need to monitor a directory for files. When a file is moved into this
direcotry I need some sort of event to be called and the file will then
be picked up.
I have done this type of thing using MFC, and used FindFirstFile, making
a call to that ever x milliseconds. I am just wondering if .NET has
something different to offer for problems like this ?

Regards,

Steven

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #4
Ok thanks for the advice.

This is the what I have done:

Created a Windows service which uses a FileSystemWatcher object. So
anytime a file gets move into the directory, the appropiate event is
being. I take the filename(s) and add them to a List. This is being
processed on a thread. I have another thread which is working through
the array (take the first element, process it and remove it from array).
The problem I encountered was when the service started up, the
FileSystemWatcher wouldnt detect files already in the direcotry, so I
had to use a FileInfo on startup, take the filenames in the direcotry
and copy them to the List.

Havent fully tested this yet, but it does look like its working.

Anyone got any thoughts on this method of processing ?

Regards,

Steven

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #5

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

Similar topics

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...
4
by: kimpton | last post by:
Hi, My App running on my local machine is trying to access apsx and ascx pages via a virtual directory (see earlier post) that points to a share on a different machine. I can now access .aspx...
2
by: Greg Allen | last post by:
I know this has been discussed before, and have found some documentation about it on the web. But nothing has fixed my problem. I am running the 1.1 .NET framework, SP1. I have a web...
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...
1
by: rachana | last post by:
Hello, I have got one asp.net application which works fine on my local machine. When moved on the server, I get error, Server Error in '/MyApplication' Application....
0
by: etropic | last post by:
Other comments say that this is the ASP.NET account not having rights. I have added the EVERYONE group to FULL CONTROL on ALL LEVELS of the noted web site directory structure... What is odd to...
0
by: William Sullivan | last post by:
I've got a 2.0 app that is crashing prior to the first page being displayed. I'm getting a "FileNotFoundException" with the message that a module wasn't found. No word on the module that is...
0
by: =?Utf-8?B?UmFmYWVsIEFtb3JpbQ==?= | last post by:
Hello Guys, I have an application that is installed on three different data centers across the world (exactly the same environment and installed files for each one). I got some errors from...
0
by: mr t | last post by:
Is there anyway to turn off visual studio file monitoring? It is interfering with my web application debugging. here is a problem: sometimes, BUT NOT ALL THE TIMES, when I create a directory...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.