 |
|
 |
It can even watch Winrar's creating file and deleting file action. That's what many others failed to do.
I love this game, but no time wait for me to play!
|
|
|
|
 |
|
 |
I took your idea, converted it to C#, and instead of using a timer, used a background thread to monitor the folder. I' writing an article about FileSystemWatcher, and wanted to let you know your code was appreciated. Credit will be given for your original idea, and I'll post a link here when the article has been submitted..45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
 |
|
|
 |
|
 |
Your file watch utility looks like a great tool; however, I have run into some problems trying to get the application working. When I attempt to start the app, either from within Visual Studio 2008 or directly from the exe, I receive the following error,
"Error while trying to run project: Unable to start program 'C:\Workspace\AdvancedFSWatcher\bin\Debug\AdvancedFSWatcher.exe'. The application has failed to start because the application configuration is incorrect. Review the manifest file for possible errors. Reinstalling the application may fix this problem. For more details, see the application event log."
When I investigate the event log, here is what I find,
"Source: SideBySide
Type: Error
Event ID: 59
Description: Generate Activation Context failed for C:\Workspace\AdvancedFSWatcher\bin\Debug\AdvancedFSWatcher.exe. Reference error message: The operation completed succesfully."
Do you have any suggestions?
TIA.
|
|
|
|
 |
|
 |
I used the FileSystemWatcher class and discovered a few problems:
* If you are dealing with a local disk with write cache enabled, changed events do not seem to be raised properly when writing files to disk.
* As stated in the MSDN documentaton, the internal buffer may need to be extended to deal with event overload. Make sure you set it to an appropriate value, the FileSystemWatcher class does not provide much in the way of notification of incorrect parameters. Implement the Error event handler and look at the Exception thrown if you see unexpected results.
* If too many events are raised at once, the class throws an exception - again, remember to implement the error event handler.
* As stated in this artcile the class is not capable of reinitiating watching if network connectivity is lost.
* Watching network drives worked fine for me as long as I use UNC paths (mapped drive letters appear to generate no events at all).
* If you run too frequent calls you could see the error "the network bios command limit has been reached": http://support.microsoft.com/kb/810886
|
|
|
|
 |
|
 |
Some more detail: * It seems it is not just cache features of hard drives that may cause trouble. RAID controllers and the like seem to swallow all change events except the first one when the file copy / move starts. * Code Access Security can be a problem, u may need to add the URL with full trust. My Computer => Runtime Security Policy => Machine => Code Groups => All_Code. Expand, and right click to create a new group. Use a URL condition type, type in your URL. Something like: file://\\srvname\sharename\* . Set full trust. If this works you should try to eliminate the full trust in favor of the minimum rights that work. In summary: don't trust this class. It looks great, and is great when it works. It just never works.
|
|
|
|
 |
|
 |
Glytzhkof wrote: In summary: don't trust this class.
You mean don't trust the FileSystemWatcher class, or this extension of it?
It's certain not the author's fault that the base class is a steaming pile to begin with. It looks to me like he's doing the best he can with what Microsoft provided.
I'm not really sure that Microsoft intended FileSystemWatcher for network shares, especially after all of problems everyone's pointed out regarding that kind of use..45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
 |
|
 |
I meant the FileSystemWatcher in general of course - it is a leaky abstraction if ever there was one. The author did fine with his additions, I just wanted to warn people not to rely on this base class without testing the issues I mentioned (hence the detailed list). Thanks for pointing out that it wasn't clear what class I was talking about, no complaints about this extension.
|
|
|
|
 |
|
 |
Hello,
I am using filesystem watcher for H drive which is USB Drive.
it's working fine.
when i am paste a file into H Drive. i want path of copying file where from file is copied.
Thanks
Anubhava Dimri
|
|
|
|
 |
|
 |
Can I get the user name who access the file
janjua
|
|
|
|
 |
|
 |
I have the same but I did't found an answer
|
|
|
|
 |
|
 |
:-> :->
George!
Thanks so much for Sharing!
You rock. Truely well done!
Tim
|
|
|
|
 |
|
 |
Please help.
I would love to try this code out, but can't get the link to the download working!
Cheers
|
|
|
|
 |
|
 |
Thanks for your code first. I have a recommendation.
Private Sub _myTimer_Elapsed should check the EnableRaisingEvents to make the code more consistent.
If EnableRaisingEvents = False then
Return ' without further processing
End IF
This is because when I use the Advanced FileSystemWatcher, I new() an instance but have not specified the Path yet. There is still exception "The path is not of a legal form." raised.
|
|
|
|
 |
|
 |
Hi, I really appreciate the code you have developed...
I am using your code for my project.
I need help to determine the source file.
i.e.
if a file is copied from source to destination and the destination folder is being monitored then a "file created" Event will be triggered and we get the file created with the proper path..
Now i want that the file copied from (Source path)also.
Hope you got me.
Any help are thankful.
Dinesh Gadewal
Patni Computer Systems
|
|
|
|
 |
|
 |
Dinesh,
The only way you can get the Source path is to watch that folder as well.
If you are Copying the file, then you would not see an event on the source path during the Copy. However if you do a MOVE you should see a file deleted event on the source path, and a file created on the destination path.
The only other thing you could do, in the event of a Copy, is modify the source file, just prior to copying it, say change the date created or something, then you should see a file changed event in the source path, But again you must also be watching that path as well.
HTH
Get access to awsome .Net Videos at www.learnVisualStudio.net
|
|
|
|
 |
|
 |
Hi,
The idea is bit tricky, will work but i am afraid cause when it comes to generalizing it would cause problem.
A new drive can be plugged any time keeping watch on them would cause problem at runtime...
Isnt there a "COPY EVENT" which windows uses and VB .NET can track that event???
If that is possible, it would solve a lot problems for me...
Any help is thankful.
Regards,
Dinesh
|
|
|
|
 |
|
 |
I've used FSW before, and like you ended up writing a wrapper to add 'missing' functionality.
Spedifically, the FSW.FileCreated event fires when a file has STARTED being created. This is no use if you try to do something with a file as soon as you get the notification, i.e. like read the contents, or even worse, move it.
I changed the FileCreated Event to STARTFileCreated, and added a ENDFileCreated event of my own.
Another major limitation is that the FSW can only monitor ALL files (*.*) or ONE type of file (e.g *.txt).
FSW is good, but it took me ages to make it do what I actually want. There are some discussions on this on MSDN Technical forums (i'm Anarchy), look here http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=659823&SiteID=1[^] if you're interested
Ade
|
|
|
|
 |
|
 |
Jon_dylon,
I understand what you are talking about, we have a work around, and basicaly we create a "DONE" file that we look for and that is put in the folder after the file we want is in the folder.
I would be interested in looking at what you did to add the EndFileCreated event.
Thanks
Get access to awsome .Net Videos at www.learnVisualStudio.net
|
|
|
|
 |
|
|
 |
|
 |
Jon,
I went to the link and saw what you were doing. I love the way you spun it up on a background thread. Nicely done!
I have modified my Advanced File System watcher to include your events. I was wondering if I could get your permission to include it with mine, and post the new version up here?
I would of course give you props for your code in the source code.
Thanks again
George
Get access to awsome .Net Videos at www.learnVisualStudio.net
|
|
|
|
 |
|
 |
Another solution that I came up with is:
1) When the file creation event gets fired..
2) Open another filesystem watcher only on that file and wait for NotifyFilters.LastWrite
3) When LastWrite gets fired, he is done copying that file -> and you close the watcher for that file:
|
|
|
|
 |
|
 |
Stotti, I'll give that a try looks like it might work, is this something you've tried?
|
|
|
|
 |
|
 |
Yes! Here is an example:
// main filesystem watcher
FileSystemWatcher fsWatcher = new FileSystemWatcher();
fsWatcher.Created +=new FileSystemEventHandler(fsWatcher_Created);
// to keep track of the subwatchers..
Hashtable htWatchers = new Hashtable();
private void fsWatcher_Created(object sender, FileSystemEventArgs e)
{
FileSystemWatcher subWatcher = new FileSystemWatcher();
subWatcher.Changed +=new FileSystemEventHandler(subWatcher_Created);
subWatcher.Path = e.FullPath.Substring(0,e.FullPath.LastIndexOf('\\'));
subWatcher.Filter = e.Name.Substring(e.Name.LastIndexOf('\\')+1);
subWatcher.NotifyFilter = NotifyFilters.LastWrite;
subWatcher.EnableRaisingEvents = true;
if (htWatchers.ContainsKey(e.FullPath))
{
htWatchers.Remove(e.FullPath);
}
htWatchers.Add(e.FullPath,subWatcher);
}
// now the new file copy should be done..
private void subWatcher_Created(object sender, FileSystemEventArgs e)
{
this.textBox_eventWindow.AppendText(e.Name + ": " + e.ChangeType.ToString() + "\r\n");
if (htWatchers.ContainsKey(e.FullPath))
{
htWatchers.Remove(e.FullPath);
}
}
|
|
|
|
 |
|
 |
thanks man, I'll look at using that!
|
|
|
|
 |