P
PadovaBoy
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 to use the same
system in many web-site.
I have just write some line of code...but i have a problem:
when i change the name of a file..i fire-up the Application_end events
.... why?
how i can meange the event of the filesystemwatcher?
Tnx at all for any suggestion.
Please ...escuse me for my english!!!
Bye
MyCode:
[GLOBAL.ASAX]
<%@ Application language="VB" inherits="myGlobal" Classname="MainApp"
debug="true" %>
[GLOBAL.VB]
Protected Sub Application_start(sender As Object, e As EventArgs)
'myWhatcher is the my object that will be store in the application
Dim objMyWath as new myWhatcher(Server.MapPath("/repository/") )
try
Application.lock()
Application.Add( "A_objMyWath" , objMyWath )
catch ex as exception
...
finally
application.unlock()
end try
end sub
Public Sub Application_End(sender As Object, e As EventArgs)
Dim fsw = Application("A_objMyWath")
Application.Remove( "A_objMyWath" )
fsw.Dispose()
end sub
----------------------------
[myWhatcher.vb]
public class myWhatcher
'make a FileSystemWatcher with events..
protected WithEvents fsw as new System.IO.FileSystemWatcher
'the path to monitorize
Public pathToAnalize as String
Public Sub New(ByRef path As String)
pathToAnalize = path
'set the FileSystemWatcher object
fsw.IncludeSubdirectories = True
fsw.Path = pathToAnalize
fsw.EnableRaisingEvents = True
end sub
'function fired-up by the event (rename)
Private Sub fsw_OnRename(ByVal sender As System.Object, ByVal e As
System.IO.RenamedEventArgs) Handles FSW.Renamed
Dim swz As StreamWriter = New StreamWriter("L:\pippo\test.txt ")
try
If System.IO.Directory.Exists(e.FullPath) Then
... some operation
End If
catch ex as Exception
end try
End Sub
public sub dispose()
fsw.dispose()
end sub
end class
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 to use the same
system in many web-site.
I have just write some line of code...but i have a problem:
when i change the name of a file..i fire-up the Application_end events
.... why?
how i can meange the event of the filesystemwatcher?
Tnx at all for any suggestion.
Please ...escuse me for my english!!!
Bye
MyCode:
[GLOBAL.ASAX]
<%@ Application language="VB" inherits="myGlobal" Classname="MainApp"
debug="true" %>
[GLOBAL.VB]
Protected Sub Application_start(sender As Object, e As EventArgs)
'myWhatcher is the my object that will be store in the application
Dim objMyWath as new myWhatcher(Server.MapPath("/repository/") )
try
Application.lock()
Application.Add( "A_objMyWath" , objMyWath )
catch ex as exception
...
finally
application.unlock()
end try
end sub
Public Sub Application_End(sender As Object, e As EventArgs)
Dim fsw = Application("A_objMyWath")
Application.Remove( "A_objMyWath" )
fsw.Dispose()
end sub
----------------------------
[myWhatcher.vb]
public class myWhatcher
'make a FileSystemWatcher with events..
protected WithEvents fsw as new System.IO.FileSystemWatcher
'the path to monitorize
Public pathToAnalize as String
Public Sub New(ByRef path As String)
pathToAnalize = path
'set the FileSystemWatcher object
fsw.IncludeSubdirectories = True
fsw.Path = pathToAnalize
fsw.EnableRaisingEvents = True
end sub
'function fired-up by the event (rename)
Private Sub fsw_OnRename(ByVal sender As System.Object, ByVal e As
System.IO.RenamedEventArgs) Handles FSW.Renamed
Dim swz As StreamWriter = New StreamWriter("L:\pippo\test.txt ")
try
If System.IO.Directory.Exists(e.FullPath) Then
... some operation
End If
catch ex as Exception
end try
End Sub
public sub dispose()
fsw.dispose()
end sub
end class