Question

Locked

File system watcher problem.

By heavey4 ·
Could someone please tell me where I am going wrong with this code please, it does'nt go into the "logchange" sub:

Imports System
Imports System.IO
Imports System.IO.File
Imports System.Diagnostics
Imports System.Data
Imports System.Data.OleDb

Public Class MainForm
Public watchfolder As FileSystemWatcher

Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
txtPath.Text = "H:\Test\Parent\Arrive"
End Sub

Public Sub logchange(ByVal source As Object, ByVal e As System.IO.FileSystemEventArgs)

If e.ChangeType = IO.WatcherChangeTypes.Created Then
Dim MyConnection As OleDbConnection
If Path.GetExtension(e.FullPath).ToUpper = ".XLS" Then
Try
''my processing code here
Catch ex As Exception
MyConnection.Close()
End Try
End If
End If
End Sub
Public Function FolderExists(ByVal FolderPath As String) As Boolean
Dim f As New IO.DirectoryInfo(FolderPath)
Return f.Exists
End Function

Public Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click

watchfolder = New System.IO.FileSystemWatcher()
'This is the path we want to monitor
If FolderExists(txtPath.Text) = True Then
watchfolder.Path = txtPath.Text

'event handlers
AddHandler watchfolder.Created, AddressOf logchange

watchfolder.EnableRaisingEvents = True
Else
MessageBox.Show("Invalid Path, Please try another", "Incorrect Path", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If

End Sub
End Class

I had this working about two days ago but the file was deleted on me and I can't get it working now to save my life.
Thanks in advance colonel-yum-yum

This conversation is currently closed to new comments.

3 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Collapse -

This might help you...

http://www.codeproject.com/KB/cs/fswatcher.aspx

When you get it back and working make sure you DO A BACKUP.
Please post back if you have more problems or questions.

Collapse -

Thanks for your reply

by heavey4 In reply to This might help you...

Thank you for replying so quickly but I got it working last night. It always seems to be small things that are missing rather than say a full class!

Back to Windows Forum
3 total posts (Page 1 of 1)  

Related Discussions

Related Forums