Hello all,
I've been working on an example from vb-helper.com and trying to modify it to be able to apply to a service. Basically, this is going to monitor a directory (using the FSW), then when a new PXP file enters, it's gonna take the info out of the file, and put it into another file. Phew! But right now, I'd like for this to just delete it from the named directory...Please o please help I am up to my ears! My code is posted below. Thanks very much in advance!!! I love reading this forum!
Imports System.ServiceProcess
Imports System.IO
Public Class svcPxpParser
Inherits System.ServiceProcess.ServiceBase
Private strWatchDir As String
Private WithEvents fswDir1 As FileSystemWatcher
Private Overloads Sub OnStart(ByVal sender As System.Object, ByVal e As System.EventArgs)
'Handles MyBase.Load lstFiles.Items.Add(Now.ToString() & " Starting")
' Get the path to the directory we will watch
strWatchDir = "C:\Documents and Settings\Administrator\Desktop\D\Provshare\Remsas\train\IDS\"
'strWatchDir = strWatchDir.Substring(0, strWatchDir.LastIndexOf("\"))
'strWatchDir &= "\Files"
' Make the FileSystemWatcher.
fswDir1 = New FileSystemWatcher
fswDir1.Path = strDirWatch
fswDir1.NotifyFilter = 0
fswDir1.NotifyFilter = fswDir1.NotifyFilter Or NotifyFilters.FileName Or NotifyFilters.Size
fswDir1.EnableRaisingEvents = True
' Process any files that already exist.
ProcessExistingFiles(strWatchDir)
End Sub
' Process existing files.
Private Sub ProcessExistingFiles(ByVal directory_name As String)
Dim dir_info As New DirectoryInfo(directory_name)
Dim file_infos As FileInfo() = dir_info.GetFiles()
For Each fi As FileInfo In file_infos
ProcessFile(fi.FullName)
Next fi
End Sub
' Process a file.
Private Sub ProcessFile(ByVal file_name As String)
lstFiles.Items.Add(Now.ToString() & " Processed " & file_name)
File.Delete(file_name)
End Sub
Protected Overrides Sub OnStop()
' Add code here to perform any tear-down necessary to stop your service.
End Sub
End Class
I've been working on an example from vb-helper.com and trying to modify it to be able to apply to a service. Basically, this is going to monitor a directory (using the FSW), then when a new PXP file enters, it's gonna take the info out of the file, and put it into another file. Phew! But right now, I'd like for this to just delete it from the named directory...Please o please help I am up to my ears! My code is posted below. Thanks very much in advance!!! I love reading this forum!
Imports System.ServiceProcess
Imports System.IO
Public Class svcPxpParser
Inherits System.ServiceProcess.ServiceBase
Private strWatchDir As String
Private WithEvents fswDir1 As FileSystemWatcher
Private Overloads Sub OnStart(ByVal sender As System.Object, ByVal e As System.EventArgs)
'Handles MyBase.Load lstFiles.Items.Add(Now.ToString() & " Starting")
' Get the path to the directory we will watch
strWatchDir = "C:\Documents and Settings\Administrator\Desktop\D\Provshare\Remsas\train\IDS\"
'strWatchDir = strWatchDir.Substring(0, strWatchDir.LastIndexOf("\"))
'strWatchDir &= "\Files"
' Make the FileSystemWatcher.
fswDir1 = New FileSystemWatcher
fswDir1.Path = strDirWatch
fswDir1.NotifyFilter = 0
fswDir1.NotifyFilter = fswDir1.NotifyFilter Or NotifyFilters.FileName Or NotifyFilters.Size
fswDir1.EnableRaisingEvents = True
' Process any files that already exist.
ProcessExistingFiles(strWatchDir)
End Sub
' Process existing files.
Private Sub ProcessExistingFiles(ByVal directory_name As String)
Dim dir_info As New DirectoryInfo(directory_name)
Dim file_infos As FileInfo() = dir_info.GetFiles()
For Each fi As FileInfo In file_infos
ProcessFile(fi.FullName)
Next fi
End Sub
' Process a file.
Private Sub ProcessFile(ByVal file_name As String)
lstFiles.Items.Add(Now.ToString() & " Processed " & file_name)
File.Delete(file_name)
End Sub
Protected Overrides Sub OnStop()
' Add code here to perform any tear-down necessary to stop your service.
End Sub
End Class