Hello,
Could someone assist me with the creation of a windows service in VB.net 2008 to copy a text file from one location to another location?
The source location will have one or more text files. If there are no files there then do nothing, otherwise move the file to teh new location specified.
I have following this site
http://www.codeguru.com/vb/gen/vb_system/services/article.php/c4825/Creating-a-Windows-Service-in-VBNET.htm[
^]
The whole code in the windows service is as follows:
Imports System
Imports System.IO
Imports Microsoft.VisualBasic.FileIO
Public Class Service1
Protected Overrides Sub OnStart(ByVal args() As String)
' Add code here to start your service. This method should set things
' in motion so your service can do its work.
Timer1.Enabled = True
End Sub
Protected Overrides Sub OnStop()
' Add code here to perform any tear-down necessary to stop your service.
Timer1.Enabled = False
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim diInward As DirectoryInfo
Dim fiInward As FileInfo()
Dim intInFiles As Integer = 0
'Checks for all the file in the location where code is IMF
Dim filename As String = Nothing
Dim di As New DirectoryInfo("C:\WFC_INWARD")
Dim fiArr As FileInfo() = di.GetFiles()
'1. Check for inward source files
diInward = New DirectoryInfo("C:\WFC_INWARD")
fiInward = diInward.GetFiles("*.*")
intInFiles = fiInward.Length
If intInFiles > 0 Then
For Each disfri In fiArr
Dim getfilename As String = Nothing
getfilename = Path.GetFileName(disfri.Name) 'eg. WFCInwardfile.bsp
File.Move("C:\WFC_INWARD" & "\" & getfilename, "C:\WFC_INWARD\ServiceTest" & "\" & getfilename) 'move the processed file to the processed location
Next
Else
Exit Sub
End If
End Sub
End Class
I have installed the service and it shows as running but nothing is happening, I mean the test text file in the source location is still there and is not being copied to the destination location. Please advise what I should do to get this working.
Thanking you all in advace.