473,386 Members | 1,720 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,386 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 2028
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.