473,763 Members | 9,161 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

FileSystemWatch er

Hi,
I have a little application that watches a FTP folder. When a file is
uploaded, it takes that file and moves it to another folder on the same
server.
Here are a couple of lines from my C# app:

FileSystemWatch er watcher = new FileSystemWatch er();
watcher.Created += new FileSystemEvent Handler(OnChang ed);

My problem is that my folder watcher does not know when the file is finish
uploading. So if the file is 3mb my file watcher moves the file before it is
finished uploading, and the resulting new file in the new folder is only like
24k.

How can I "KNOW" when the file is finish uploading? Is there some type of
windows event I can watch?

Thanks,
Michael

Aug 24 '06 #1
4 7406
>
How can I "KNOW" when the file is finish uploading? Is there some type of
windows event I can watch?
I am not sure if this is an optimal solution, but if you can get a write
lock on the file, nobody else is having a write lock on it. (just don't
overwrite it)

Try to open the file in 'append' mode or 'write' mode, and check the result.

/Søren
Aug 24 '06 #2

Michael wrote:
Hi,
I have a little application that watches a FTP folder. When a file is
uploaded, it takes that file and moves it to another folder on the same
server.
Here are a couple of lines from my C# app:

FileSystemWatch er watcher = new FileSystemWatch er();
watcher.Created += new FileSystemEvent Handler(OnChang ed);

My problem is that my folder watcher does not know when the file is finish
uploading. So if the file is 3mb my file watcher moves the file before it is
finished uploading, and the resulting new file in the new folder is only like
24k.

How can I "KNOW" when the file is finish uploading? Is there some type of
windows event I can watch?

Thanks,
Michael
I found this and thought it might help you:

http://www.jasonstorch.com/

"If you have read my previous post on the FileSystemWatch er control, I
posted code for a simple service that runs in the background ad copies
files from one server to another. Basically, the fix is to add the
following few lines of code to the create and change events:

while (!File.Exists(s ample.file))
{
//keep looping until the file is unlocked.
}"

The page has other code as well. Hope this helps.

Aug 24 '06 #3
Hi,
couldn't this cause an endless loop?
Michael

"ne***********@ gmail.com" wrote:
>
Michael wrote:
Hi,
I have a little application that watches a FTP folder. When a file is
uploaded, it takes that file and moves it to another folder on the same
server.
Here are a couple of lines from my C# app:

FileSystemWatch er watcher = new FileSystemWatch er();
watcher.Created += new FileSystemEvent Handler(OnChang ed);

My problem is that my folder watcher does not know when the file is finish
uploading. So if the file is 3mb my file watcher moves the file before it is
finished uploading, and the resulting new file in the new folder is only like
24k.

How can I "KNOW" when the file is finish uploading? Is there some type of
windows event I can watch?

Thanks,
Michael

I found this and thought it might help you:

http://www.jasonstorch.com/

"If you have read my previous post on the FileSystemWatch er control, I
posted code for a simple service that runs in the background ad copies
files from one server to another. Basically, the fix is to add the
following few lines of code to the create and change events:

while (!File.Exists(s ample.file))
{
//keep looping until the file is unlocked.
}"

The page has other code as well. Hope this helps.

Aug 24 '06 #4
I would use a System.Threadin g.Timer delegate (after the dir changed event)
to kick off every minuite or so to check the "CanWrite" status or catch the
open exception. This assumes the FTP process has opened the file with
exclusive write access, which it should. If it incorrectly opens the file
with shared read/write, then another solution may be needed.

--
William Stacey [MVP]

"Michael" <Mi*****@discus sions.microsoft .comwrote in message
news:C8******** *************** ***********@mic rosoft.com...
| Hi,
| couldn't this cause an endless loop?
| Michael
|
| "ne***********@ gmail.com" wrote:
|
| >
| Michael wrote:
| Hi,
| I have a little application that watches a FTP folder. When a file is
| uploaded, it takes that file and moves it to another folder on the
same
| server.
| Here are a couple of lines from my C# app:
|
| FileSystemWatch er watcher = new FileSystemWatch er();
| watcher.Created += new FileSystemEvent Handler(OnChang ed);
|
| My problem is that my folder watcher does not know when the file is
finish
| uploading. So if the file is 3mb my file watcher moves the file
before it is
| finished uploading, and the resulting new file in the new folder is
only like
| 24k.
|
| How can I "KNOW" when the file is finish uploading? Is there some
type of
| windows event I can watch?
|
| Thanks,
| Michael
| >
| I found this and thought it might help you:
| >
| http://www.jasonstorch.com/
| >
| "If you have read my previous post on the FileSystemWatch er control, I
| posted code for a simple service that runs in the background ad copies
| files from one server to another. Basically, the fix is to add the
| following few lines of code to the create and change events:
| >
| while (!File.Exists(s ample.file))
| {
| //keep looping until the file is unlocked.
| }"
| >
| The page has other code as well. Hope this helps.
| >
| >
Aug 24 '06 #5

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

Similar topics

4
9120
by: Josh Usovsky | last post by:
I'm setting up a watched folder using FileSystemWatcher. When I drop a small file into the watched folder, I can respond to a .Created event and process the file with other code. However, if I try copying a large file into the watched folder, the .Created event is fired off immediately and not when the file is finished copying. I have tried waiting for a certain number of .Changed events to be fired after the initial .Created event, and...
1
3332
by: Troy Murphy | last post by:
How do I prevent the FileSystemWatcher event to keep firing while the file is being created? When copying a file to the watched folder, the event fires a dozen or more times! Also, the documentation states that if more than one file is copied to the folder at the same time, a cache will queue them up for processing, but when I drop 3 files into this folder, only the 1st (sometimes the first two) cause the event to fire. Thanks, Troy
7
4123
by: Allen Anderson | last post by:
I'm trying to figure out a way to catch when a file has been written to a directory. I currently have it where I can catch when the file begins writing, but this isn't helpful as I need to know when its done. Does anyone know the right combination of flags to use to catch when the file has been written and closed? (here is my current code). // member variable FileSystemWatcher watcher = new FileSystemWatcher();
2
2231
by: Jet Leung | last post by:
Hi all, I had made a program to watching files in my directory. I had used a instance of FileSystemWatcher to do my work.And I had add some events of the FileSystemWatcher , for example onChange, onRename and so on. And I had made this program as a windows service.As I know, if I delete a file from my directory, this behavior will active this program and do something what I want to do. But after I install this program as a windows service...
13
9176
by: David | last post by:
I have been working on trying to write a directory watcher service. One of the requirments is that it be able to watch multiple directories, not sub directories of one parent directory, but just multiple directories. I have hit a snag and don't know how to get around it. Basically I read in a list of directories from the app.config and stuff them into an array, so that I have something like this: sDirsToWatch = "C:\Temp"
3
14307
by: Stampede | last post by:
Hi, I want to use the FileSystemWatcher in a Windows Service. I read an article, where the author created the FileSystemWatcher object in a seperate thread and when the event is fired, he started a working thread for processing the file, created a new FileSystemWatcher (as he said for real time processing), and then called the join method for the first thread. I can't really see the sence in this. Aren't the events of the...
20
4496
by: J-T | last post by:
We are working on an asp.net application which is a 3-tier application.I was aksed to create a component which monitors a folder and gets the file and pass them to a class library in our business logic layer(so far so good and easy).I initialize my class which is using a FileSystemWatcher in my Global.asax and everything works fine.I have found FileSystemWatcher class not very reliable and sometimes it behavies unexpectedly.I'm afriad that...
12
7459
by: ljh | last post by:
Has anyone else noticed that the FileSystemWatcher raises the changed event twice when a file is changed? Do you have any idea why this is the case?
5
24192
by: Goran Djuranovic | last post by:
Hi all, I have a file system watcher service that works fine on a local hard drive, but will not work across the network. I tried both: mapping the drive and "\\..." path both no luck. I don't receive any errors, it is just that FileSystemWatcher doesn't see any files dropped in the folder. What could be wrong? Thanks Goran
5
5606
by: =?Utf-8?B?Sm9obiBT?= | last post by:
I am trying to find out if there is a way to tell if there is already a filesystemwatcher (created by a webservice) monitoring a folder. I have a webservice that creates a filesystemwatcher, monitors a folder and then returns the contents of the new/changed files. However, if the client app loses connection to the webservice without closing the filewatcher, and then reconnects (and thus creates a new watcher), I believe I end up with...
0
9564
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9387
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10148
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9938
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9823
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8822
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6643
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3528
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.