|
My program watches C:\Incoming using .Net 3.5's FileSystemWatcher with the following paramters:
FileSystemWatcher fsw = new FileSystemWatcher();
fsw.Created += new FileSystemEventHandler(fsw_Created);
fsw.Path = @"C:\Incoming";
fsw.IncludeSubdirectories = false;
fsw.EnableRaisingEvents = true;
static void fsw_Created(object sender, FileSystemEventArgs e)
{
while (!FileReady.isFileReady(e.FullPath))
{
Thread.Sleep(2000);
}
}
The C:\Incoming directory is shared for network access. If I manually copy a file to the directory from another machine it sees it fine and processes it. However, if I download a similar (or the same) file from a website in IE and have it save to that mapped drive (shared directory) nothing happens.
Anyone know why FileSystemWatcher doesn't see it and how to resolve the issue?
- Joshua
|
|
|
|
|
I just tried it with your code and it seemed to work fine. I replaced all your logic in fsw_Created with a MessageBox.ShowDialog and it popped up 2 or 3 times when I downloaded and saved a file to the C:\Incoming folder.
Perhaps the logic in FileReady.isFileReady is doing something funky? Maybe it's throwing an exception? One thing to watch out for is that IE downloads the file to a temporary folder first, then copies it over from that temp folder to the destination. That could maybe cause some issues.
|
|
|
|
|
Thank you for testing the code. My question is: Did you save the file downloaded from IE to a mapped drive shared on a second computer and not to a local directory?
|
|
|
|
|
There is no resolution to the problem. The FSW was designed to work with local filesystems, not network ones. Read up on this list[^].
|
|
|
|
|
Dave:
Thank you for your response. From what I gather in the google search you sent me it seems people are trying to tell the FileSystemWatcher server to watch a mapped drive (i.e. creating a mapped drive to a share somewhere else, setting it as M:, and then telling the FSW to watch M:\).
That is not what I'm doing. I have the FSW installed as a service on a server running local to that machine so that it is watching the local C:\Incoming. So I don't think it should matter if I'm copying a file locally or via the network to that shared folder from a third-party machine.
Here is some additional information that may help explain where I am. I can copy a file to that share from my workstation and the FSW will work no problem. But if I download a file on my workstation and tell IE to save it to my I: drive (which is a mapped drive to that share on the server where FSW is) nothing happens.
So, I'm thinking that it has something to do with how IE is writing the file to a share and not triggering a CREATE even for FSW to see? Make sense.
|
|
|
|
|
I misunderstood what you're doing.
Well, this may change things a bit. IE doesn't write the file to the location you tell it to. It writes the content of the file to the Temporary Internet Files folder then either moves the file to the final location or copies it if the file is on a different volume, then deletes the file in the TIF folder.
|
|
|
|
|
I kinda of figured that was the process that IE followed but it doesn't make sense that when it copies the file to the network share it doesn't look just like any other simple copy process so that FSW will see the Created event.
Perhaps this is a bug?
|
|
|
|
|
Does not anyone have an answer?
|
|
|
|
|
Hi,
I have very similar problem.
I'm running FSW as a service and watch for the all events. Folder contains photos and when the new one dropped or changed/renamed/deleted we make some resizing and put results in two other unwatched folders.
The problem raise up when I try to download something from internet and as destination set the watched folder.
We using firefox and if we choose "Save image as" everything works ok, but if we have a link to photo and choose "Save link as" we run into problems.
First, there is issue with file locking. We try to solve it using System.IO.FileStream. If we get error we wait 1000ms and try again... I think you use similar logic in your FileReady.isFileReady. Sometimes file doesn't processed.
Next, sometimes we got firefox error (can't write destination folder). We try to use different options in filestream (readwrite, shared...) but with no success.
I think that solution might be making some type of log which contains file names, and process files later.
The strange thing is when we copy files to watched directory even from a source on a slow link everything works ok. Sync script runs on the same machine running FSW service (we pull files from distant folder and put them into local one watched by FSW)
Main problem is file locking issue and multiple events for the same file (created, deleted, created, multiple changed...) while downloading from internet using firefox (firefox crate destination file with size 0, .part file which is used as temp file while downloading, and finally probably copy .part into destination file when download finished into .part file). It happens regardless the size of file downloaded (needed time for downloading).
I'm interested in your logic you use in FileReady.isFileReady. Could you please give some hint about it?
Thanks
Goran
|
|
|
|
|
Sure, nothing I'm doing is proprietary in my code and in fact some of the code from that class was found online. Here is the code:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
namespace WQADEncoder
{
public class FileReady
{
public static bool isFileReady(string File)
{
FileInfo fi = new FileInfo(File);
try
{
FileStream fs = fi.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.None);
fs.Close();
fs.Dispose();
Thread.Sleep(5000);
return true;
}
catch
{
return false;
}
}
}
}
I still haven't found a solution the problem that works with FSW directly. I could see adding a method & timer to check the directory ever x minutes and then scraping files that FSW missed but why should I have to do that? Microsoft, where are you!? FSW has been a pain in but for years now, is used frequently, but yet it still works the same way? Helps us out MS!
|
|
|
|
|
Thanks for your code...
Yes, help us out MS!
Goran
|
|
|
|
|
hi every one imagine that i am in a local network how can i retrieve my servers ip with socket programming? i know that (hostInfo.AddressList[0]) retrieve my local ip but i need my server ip like the ones that site(ip-address.com) retrieve
thatks
|
|
|
|
|
run the command net view from windows as well as net group, might give you the server name. (Type net at the command line for a full list of options)
|
|
|
|
|
What do you mean, the one behind your adsl box for instance ?
|
|
|
|
|
mehrdad333 wrote: how can i retrieve my servers ip
One of two ways: keep it in a file and do a manual lookup, or make it known to a DNS server, and look it up through that. There is no way that software can guess an IP address without using some sort of lookup table that already contains the information.
MVP 2010 - are they mad?
|
|
|
|
|
Does anyone have any AppDev training that I can borrow / buy for cheap on the following topics: Visual Studio 2008 C# / ASP.NET / MVC / LINQ?
Thanks
Brian
|
|
|
|
|
Take a look here[^], here[^], here[^], and here[^] as starters. And use Google for further research.
MVP 2010 - are they mad?
|
|
|
|
|
I have done training before, of course my training has been for tech audiences and involves hands-on code writing and not slideshows so it isn't for everyone. But it is not cheap.
|
|
|
|
|
hi all,
i am developing some image processing functionalities.i have colorful image that is RGB image.now i gave three choice that is RED ,GREEN and BLUE.now depending upon the selection , i mean in whichever order user selects the image should be generated in that way and changes should be affected in an image.
i heard that RGB , BGR , or another combination have different images , isn't it ?
please give me some idea about my question , how do i generate those different colored images ?
|
|
|
|
|
Sorry, but I have no idea what you are talking about. Perhaps you can clarify?
CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
RGB (or BGR) is merely shorthand for describing a colour combination that comprises a Red, Blue and Green component in different shades/intensities. It does not matter which order you take the values as long as you specify them in the right order within your image data.
MVP 2010 - are they mad?
|
|
|
|
|
|
hi all,
i am clarifying my problem here.i have picture box in which i am retrieving an image.i have three buttons of red,green and blue.whenever i click on red button,image should show red part only and other should be look black and same should happen to green and blue button.
can any one suggest solution or show me the code ?
|
|
|
|
|
Is it possible to measure frequency from a person's voice....please give source code or any instruction
|
|
|
|
|