PC Review


Reply
Thread Tools Rate Thread

Copying a file after the "Created" event with FileSystemWatcher

 
 
Jason
Guest
Posts: n/a
 
      18th Oct 2004
Given a scenario where I'm monitoring a folder, once the file has been
created, I'd like to have it relocated to another folder via the
File.Copy() method.

My problem occurs when I paste a 600mb+ file into the folder I'm
monitoring. I use this magnitude of a size in order to guarantee it'll
work for smaller files.

The "created" event occurs before the file is actually completely
copied into the folder, so when I try to do File.Copy(), nothing
happens.

Is there anyway to set a NotifyFilter to respond ONLY when the file
has been "completely" created?
 
Reply With Quote
 
 
 
 
Chris Dunaway
Guest
Posts: n/a
 
      18th Oct 2004
On 18 Oct 2004 07:17:29 -0700, Jason wrote:

>
> Is there anyway to set a NotifyFilter to respond ONLY when the file
> has been "completely" created?


Not to my knowledge. I have used two methods. The first method is to have
the file placed in the folder using a temporary name and then rename it to
the expected name. Then handle the Rename event of the FileSystemWatcher.

The second is when the Create event occurs, attempt to open the file
exclusively. If that fails, then the file is still being copied in. Keep
attempting to open the file in a loop until you are successful. Then you
can perform the file.copy.

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Filesystemwatcher created event Ripley Microsoft C# .NET 2 28th Sep 2006 12:49 PM
error in "OnCreated" event of FileSystemWatcher class =?Utf-8?B?TWFoaXRh?= Microsoft C# .NET 1 12th Jul 2006 09:33 AM
Retrieving "Created By" and "Modified By" properties of a file =?Utf-8?B?RVlJSUk=?= Microsoft Dot NET 3 13th Apr 2006 06:09 PM
FileSystemWatcher.Created Event Question - Please look! Florida Development Microsoft Dot NET Framework 3 13th Sep 2004 03:58 PM
FileSystemWatcher "created" event won't fire as a service - HELP!!! Steve Microsoft VB .NET 1 12th Dec 2003 11:53 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:22 AM.