Hi all,
I have a problem with the fsw object, and maybe someone experienced with
the fsw can help me out.
First I want to a share a snippet of the code with you:
private void fsw1_Changed(object sender, FileSystemEventArgs e)
{
if (FSWConfiguration.EnableSendEmail)
{
try
{
Utilities.SendMail(
FSWConfiguration.FromWho,
FSWConfiguration.SendToEmail,
FSWConfiguration.Subject,
"", e.FullPath);
}
catch (Exception ex)
{
if (FSWConfiguration.EnableErrorLogEmail)
{
EventLog.WriteEntry("FSW", ex.ToString(),
EventLogEntryType.Error);
Utilities.LogError(ex);
}
}
finally
{
EventLog.WriteEntry("FSW", "Moving file created to" +
fsw1.Path.ToString() + e.Name.ToString() + fsw1.Path.ToString() +
"\\backup\\" + e.Name.ToString());
try
{
string source = e.FullPath;
string destination = fsw1.Path.ToString() + "backup\\" +
e.Name.ToString();
Directory.Move(source,destination);
}
catch (Exception ex)
{
EventLog.WriteEntry("FSW", "Error while trying to move file
" + e.Name + " to \backup directory. Error:" + ex.ToString(),
EventLogEntryType.Error);
}
}
}
else
{
EventLog.WriteEntry("FSW", "debugging. triggered changed event for
file " + e.FullPath.ToString());
}
}
What this piece of code should do :) is the following:
When a file has ended been written to, based on the NotifyFilter of the
fsw1 object, it should be mailed to a recipient and
then move to a folder \backup.
What it does is, make a mail 2-3-4 times mail it ok but it does not move the
file 'cause it says it is used by another process.
So my 2 questions are:
1) Why does the event fire more than once?
2) Why does it lock the file and does not let me move it?
Cheers,
Vassilis I. 2 1900
The event could be firing multiple times if you've somehow registered it
multiple times. Check to see what filenames are being passed through. What
file watch event is the method associated with?
With regards to the access problem; could be:
1. The event has fired but the operation that caused the event is still in
progress (see what event is being monitored above).
2. If the file can be accessed at the start of the handler then it may be
that the Utilities.SendMail is not closing the file. Try opening the file
exlusively at the start of the event (and then closing it).
3. Is some other process accessing the file.
It may help to use member variables for the monitorFolder and
monitorBackupFolder (reduces amount of code in the statements) as in:
File.Move(
Path.Combine(this.monitorFolder, e.Name),
Path.Combine(this.monitorBackupFolder, e.Name));
HTH
- Andy
"VI" <vi@alouette.grwrote in message news:ec**********@mouse.otenet.gr...
Hi all,
I have a problem with the fsw object, and maybe someone experienced
with the fsw can help me out.
First I want to a share a snippet of the code with you:
private void fsw1_Changed(object sender, FileSystemEventArgs e)
{
if (FSWConfiguration.EnableSendEmail)
{
try
{
Utilities.SendMail(
FSWConfiguration.FromWho,
FSWConfiguration.SendToEmail,
FSWConfiguration.Subject,
"", e.FullPath);
}
catch (Exception ex)
{
if (FSWConfiguration.EnableErrorLogEmail)
{
EventLog.WriteEntry("FSW", ex.ToString(),
EventLogEntryType.Error);
Utilities.LogError(ex);
}
}
finally
{
EventLog.WriteEntry("FSW", "Moving file created to" +
fsw1.Path.ToString() + e.Name.ToString() + fsw1.Path.ToString() +
"\\backup\\" + e.Name.ToString());
try
{
string source = e.FullPath;
string destination = fsw1.Path.ToString() + "backup\\" +
e.Name.ToString();
Directory.Move(source,destination);
}
catch (Exception ex)
{
EventLog.WriteEntry("FSW", "Error while trying to move file
" + e.Name + " to \backup directory. Error:" + ex.ToString(),
EventLogEntryType.Error);
}
}
}
else
{
EventLog.WriteEntry("FSW", "debugging. triggered changed event for
file " + e.FullPath.ToString());
}
}
What this piece of code should do :) is the following:
When a file has ended been written to, based on the NotifyFilter of the
fsw1 object, it should be mailed to a recipient and
then move to a folder \backup.
What it does is, make a mail 2-3-4 times mail it ok but it does not move
the file 'cause it says it is used by another process.
So my 2 questions are:
1) Why does the event fire more than once?
2) Why does it lock the file and does not let me move it?
Cheers,
Vassilis I.
I think this is pretty good to play with: http://msdn2.microsoft.com/en-us/lib...emwatcher.aspx
chanmm
"VI" <vi@alouette.grwrote in message news:ec**********@mouse.otenet.gr...
Hi all,
I have a problem with the fsw object, and maybe someone experienced
with the fsw can help me out.
First I want to a share a snippet of the code with you:
private void fsw1_Changed(object sender, FileSystemEventArgs e)
{
if (FSWConfiguration.EnableSendEmail)
{
try
{
Utilities.SendMail(
FSWConfiguration.FromWho,
FSWConfiguration.SendToEmail,
FSWConfiguration.Subject,
"", e.FullPath);
}
catch (Exception ex)
{
if (FSWConfiguration.EnableErrorLogEmail)
{
EventLog.WriteEntry("FSW", ex.ToString(),
EventLogEntryType.Error);
Utilities.LogError(ex);
}
}
finally
{
EventLog.WriteEntry("FSW", "Moving file created to" +
fsw1.Path.ToString() + e.Name.ToString() + fsw1.Path.ToString() +
"\\backup\\" + e.Name.ToString());
try
{
string source = e.FullPath;
string destination = fsw1.Path.ToString() + "backup\\" +
e.Name.ToString();
Directory.Move(source,destination);
}
catch (Exception ex)
{
EventLog.WriteEntry("FSW", "Error while trying to move file
" + e.Name + " to \backup directory. Error:" + ex.ToString(),
EventLogEntryType.Error);
}
}
}
else
{
EventLog.WriteEntry("FSW", "debugging. triggered changed event for
file " + e.FullPath.ToString());
}
}
What this piece of code should do :) is the following:
When a file has ended been written to, based on the NotifyFilter of the
fsw1 object, it should be mailed to a recipient and
then move to a folder \backup.
What it does is, make a mail 2-3-4 times mail it ok but it does not move
the file 'cause it says it is used by another process.
So my 2 questions are:
1) Why does the event fire more than once?
2) Why does it lock the file and does not let me move it?
Cheers,
Vassilis I. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
by: cxw0106 |
last post by:
Hello,
I have some weird problem with the FileSystemWatcher. I have developed
an application that monitors a network directory for file changes of a
certain file type. The program runs well for...
|
by: Paul |
last post by:
Hi,
I've been developing an application in VB.NET that uses the
FileSystemWatcher and a popup notification in order to tell me when files
have been downloaded.
The FileSystemWatcher code in...
|
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...
|
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...
|
by: Stampede |
last post by:
Hi,
I write an application which waits for incomming files in a specified
directory. I thought, that using the FileSystemWatcher would be the best, as
it does exactly what I need.
But now I have...
|
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...
|
by: PadovaBoy |
last post by:
Hi!
I try to develop a simple system for monitoring a sub directory of a
web site and remake an xml file every time a sub-dir change it's name.
I don't wont to use a window.service because, i want...
|
by: kmcnet |
last post by:
Hello Everyone and thanks for your help in advance. I have been battling a
problem for nearly a month with the FileSystemWatcher component. Basically,
what I am trying to do it to monitor three...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
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,...
|
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...
|
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...
| |