Re: ASP.NET Application and FileSystemWatcher
- From: "J-T" <RayAll@xxxxxxxxxxxx>
- Date: Tue, 17 May 2005 14:51:32 -0700
Here is what I have done .I have created a class and I instanciate that
class in Application_Start method of my Global.asax ere is the code:
********Gloabl.asax:
//Sets up a wacher on an specific shared folder to pickup zip files
IFPWatcherComponent ifpWacher=new
IFPWatcherComponent(ConfigurationSettings.AppSettings[ "MonitorPath"]);
********MyClass:
/// </summary>
public class IFPWatcherComponent:BusinessObject
{
string PathToMonitor=null;
public IFPWatcherComponent(string PathToMonitor)
{
try
{
this.PathToMonitor = PathToMonitor;
//Check to see if Web.config has appropriate settings
if (this.PathToMonitor.Trim().Length==0 ) return;
// Make a reference to a directory.
DirectoryInfo di = new DirectoryInfo(this.PathToMonitor);
// Create the directory only if it does not already exist.
if (di.Exists == false)
di.Create();
// create an instance of FileSystemWatcher object and assign path to
monitor
FileSystemWatcher watcher = new FileSystemWatcher();
// set necessary filters
watcher.Path = this.PathToMonitor;
//Watch for changes in FileName
watcher.NotifyFilter = NotifyFilters.FileName;
// watch zip files
watcher.Filter = "*.zip";
//Add appropriate event handler
watcher.Created += new FileSystemEventHandler(OnCreated);
watcher.EnableRaisingEvents = true;
}
catch
{
throw;
}
}
private void OnCreated(object source, FileSystemEventArgs e)
{
FileStream oImg=null;
BinaryReader oBinaryReader=null;
Uploader uploader=new Uploader();
uploader.ComeFrom="88";
uploader.Comments="comment";
uploader.CreatedByUser="test";
uploader.FileName=e.Name;
try
{
oImg = new FileStream (e.FullPath,FileMode.Open,FileAccess.Read);
oBinaryReader = new BinaryReader(oImg);
byte[] oImgByteArray = oBinaryReader.ReadBytes((int) oImg.Length);
uploader.FileBody=oImgByteArray;
uploader.RecordType=Business.IFP.RecordType.IFP_UPLOAD;
uploader.Upload();
uploader=null;
}
catch(Exception ee)
{
*******************I don't know how to handle the exception
here??***********************
}
finally
{
if (oBinaryReader!=null) oBinaryReader.Close();
if (oImg!=null) oImg.Close();
}
}
"Eliyahu Goldin" <removemeegoldin@xxxxxxxxxxxxxx> wrote in message
news:udEvR5xWFHA.3188@xxxxxxxxxxxxxxxxxxxxxxx
> Are you sure you are on the right track? A FileSystemWatcher object has to
> exist somewhere to be able to watch. An asp.net application doesn't exist
> anywhere but between a client http request and the server response. A very
> short time. Do you expect the watcher to catch something only when the
> server is busy serving client requests?
>
> Eliyahu
>
>
> "J-T" <RayAll@xxxxxxxxxxxx> wrote in message
> news:%23QPGMNxWFHA.3540@xxxxxxxxxxxxxxxxxxxxxxx
>> 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
> it
>> brings down the whole application.Is there a better way of doing this
>> **Inside Asp.Net application**.I can't use antother application like
> windows
>> service or schedault taks.Everything needs to be done is ASP.NET
>> application.
>>
>>
>> Thanks a lot
>>
>>
>
>
.
- Follow-Ups:
- Re: ASP.NET Application and FileSystemWatcher
- From: Kevin Spencer
- Re: ASP.NET Application and FileSystemWatcher
- References:
- ASP.NET Application and FileSystemWatcher
- From: J-T
- Re: ASP.NET Application and FileSystemWatcher
- From: Eliyahu Goldin
- ASP.NET Application and FileSystemWatcher
- Prev by Date: Re: ads by google
- Next by Date: Re: ASP.NET Application and FileSystemWatcher
- Previous by thread: Re: ASP.NET Application and FileSystemWatcher
- Next by thread: Re: ASP.NET Application and FileSystemWatcher
- Index(es):
Relevant Pages
|
Loading