Hi all,
I'm not sure if this is the right forum, but here goes.
I am writing a program in vb.net to read a flat file transmitted over the EDI line on AS2 protocol.
the program looks for an event to occur within the server's receiving folder. when a new file comes in, the program should shoot off an image of itself, convert the file to a usable format and turn itself off.
When I run the program and click-and-drag the file to the folder, the program works. when the file comes in through the real channels (delivery), the program does not shoot off.
I am using system.io.FileSystemWatcher in the following code:
Private Sub btnStart_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnStart.Click
Dim WatchFolder As New System.IO.FileSystemWatcher
Dim fCheck As System.IO.FileInfo = New FileInfo(txtFileName.Text)
Try
' WatchFolder.BeginInit()
If fCheck.Exists Then
' If System.IO.File.Exists(txtFileName.Text) = False Then
MsgBox("You must enter a valid path", MsgBoxStyle.OKOnly)
Else
WatchFolder.Path = txtFileName.Text
'list of filters to specify
WatchFolder.Filter = "*.in"
WatchFolder.IncludeSubdirectories = False
WatchFolder.NotifyFilter = (IO.NotifyFilters.FileName Or _
IO.NotifyFilters.LastAccess Or _
IO.NotifyFilters.LastWrite Or _
IO.NotifyFilters.CreationTime Or _
NotifyFilters.Security)
'event handlers
AddHandler WatchFolder.Changed, New FileSystemEventHandler(AddressOf LogChange)
AddHandler WatchFolder.Created, New FileSystemEventHandler(AddressOf LogCreate)
AddHandler WatchFolder.Deleted, New FileSystemEventHandler(AddressOf LogDelete)
'rename handler
AddHandler WatchFolder.Renamed, New RenamedEventHandler(AddressOf LogRename)
WatchFolder.EnableRaisingEvents = True
btnStart.Enabled = False
btnEnd.Enabled = True
End If
Catch ex As Exception
MsgBox("error: " & ex.HelpLink & vbCr & _
"----------------------------------------------------" & vbCr & _
ex.ToString & vbCr & _
"----------------------------------------------------" & vbCr & _
ex.Message)
Finally
WatchFolder.Dispose()
End Try
End Sub
is there a better option for an event watcher from vb.net? if not what should I be doing?
I am also having a hard time getting the program to work on a server. I am guessing its because of the threads created in this program. to get around these issues I have delayed the program by 30 sec to a minute where errors occur. I can accept this, but of course would like to know a better way -- tips especially.
thanks in advanced for any advice or hints.
ronze
I'm not sure if this is the right forum, but here goes.
I am writing a program in vb.net to read a flat file transmitted over the EDI line on AS2 protocol.
the program looks for an event to occur within the server's receiving folder. when a new file comes in, the program should shoot off an image of itself, convert the file to a usable format and turn itself off.
When I run the program and click-and-drag the file to the folder, the program works. when the file comes in through the real channels (delivery), the program does not shoot off.
I am using system.io.FileSystemWatcher in the following code:
Private Sub btnStart_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnStart.Click
Dim WatchFolder As New System.IO.FileSystemWatcher
Dim fCheck As System.IO.FileInfo = New FileInfo(txtFileName.Text)
Try
' WatchFolder.BeginInit()
If fCheck.Exists Then
' If System.IO.File.Exists(txtFileName.Text) = False Then
MsgBox("You must enter a valid path", MsgBoxStyle.OKOnly)
Else
WatchFolder.Path = txtFileName.Text
'list of filters to specify
WatchFolder.Filter = "*.in"
WatchFolder.IncludeSubdirectories = False
WatchFolder.NotifyFilter = (IO.NotifyFilters.FileName Or _
IO.NotifyFilters.LastAccess Or _
IO.NotifyFilters.LastWrite Or _
IO.NotifyFilters.CreationTime Or _
NotifyFilters.Security)
'event handlers
AddHandler WatchFolder.Changed, New FileSystemEventHandler(AddressOf LogChange)
AddHandler WatchFolder.Created, New FileSystemEventHandler(AddressOf LogCreate)
AddHandler WatchFolder.Deleted, New FileSystemEventHandler(AddressOf LogDelete)
'rename handler
AddHandler WatchFolder.Renamed, New RenamedEventHandler(AddressOf LogRename)
WatchFolder.EnableRaisingEvents = True
btnStart.Enabled = False
btnEnd.Enabled = True
End If
Catch ex As Exception
MsgBox("error: " & ex.HelpLink & vbCr & _
"----------------------------------------------------" & vbCr & _
ex.ToString & vbCr & _
"----------------------------------------------------" & vbCr & _
ex.Message)
Finally
WatchFolder.Dispose()
End Try
End Sub
is there a better option for an event watcher from vb.net? if not what should I be doing?
I am also having a hard time getting the program to work on a server. I am guessing its because of the threads created in this program. to get around these issues I have delayed the program by 30 sec to a minute where errors occur. I can accept this, but of course would like to know a better way -- tips especially.
thanks in advanced for any advice or hints.
ronze