akjtr
asked on
.NET File.Copy createing new zero length files when using local accounts with Windows Service
Greetings,
I have an interesting problem with a Win32 service I wrote in VB.NET that uses a FileSystemWatcher object in a Windows Service to catch new files in a directory and move them to a file share on a different domain server. The service is using the File.Copy method to copy the files and rename them. The server with the service / File.Copy code is not part of a domain and uses a local admin account (pospay) to run the service. The domain server with the destination file share has a matching pospay user account with a synchronized password. The service starts fine and successfully works ONCE to copy the new file to the share but after the initial success in copying the file intact all subsequent File.Copy operations result in new, zero length files until I restart the server. This includes changing the service to not use the domain file share location and instead use it's own desktop folder. The files are still new, zero length files with the same name as the originating file.
I have an interesting problem with a Win32 service I wrote in VB.NET that uses a FileSystemWatcher object in a Windows Service to catch new files in a directory and move them to a file share on a different domain server. The service is using the File.Copy method to copy the files and rename them. The server with the service / File.Copy code is not part of a domain and uses a local admin account (pospay) to run the service. The domain server with the destination file share has a matching pospay user account with a synchronized password. The service starts fine and successfully works ONCE to copy the new file to the share but after the initial success in copying the file intact all subsequent File.Copy operations result in new, zero length files until I restart the server. This includes changing the service to not use the domain file share location and instead use it's own desktop folder. The files are still new, zero length files with the same name as the originating file.
Imports System.IO
Imports System.Xml
Imports System.ComponentModel
Imports System.ServiceProcess
Public Class PositivePayWatcher
Inherits System.ServiceProcess.ServiceBase
Const ApDestination As String = "\\tundra2\Workgrps\FNSB\Wf Positive Pay\jct_test\ap"
Const PyDestination As String = "\\tundra2\Workgrps\FNSB\Wf Positive Pay\jct_test\py"
Const ApWatchLocation As String = "c:\\fnsb\pospay\ap"
Const PyWatchLocation As String = "c:\\fnsb\pospay\py"
Const TransferLogLocation As String = "\\tundra2\Workgrps\FNSB\Wf Positive Pay\jct_test\pospay.xml"
Private TransferType As String
Private LoggingXmlDoc As New XmlDocument
Protected Overrides Sub OnStart(ByVal args() As String)
'AP -------------------------------------------------------------------
fswAP.Path = ApWatchLocation
fswAP.NotifyFilter = IO.NotifyFilters.FileName 'watch operation/task
'PY -------------------------------------------------------------------
fswPY.Path = PyWatchLocation
fswPY.NotifyFilter = IO.NotifyFilters.FileName 'watch operation/task
'Log ------------------------------------------------------------------
If File.Exists(TransferLogLocation) Then LoggingXmlDoc.Load(TransferLogLocation)
End Sub
Private Sub WatchForChanges_Payroll(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs) Handles fswPY.Created
Dim filename As String = e.Name
Try
TransferType = "PY"
File.Copy(e.FullPath, PyDestination & "\" & filename, True) 'use built in file transfer utility to move the file and rename it csv
LogTranfer(filename, PyDestination & "\" & filename, TransferType)
Catch ex As Exception
Dim logdata As New IO.StreamWriter("c:\fnsb\wf.txt", True, Text.Encoding.ASCII)
logdata.Write(ex.Message.ToString & vbCrLf)
logdata.Close()
End Try
End Sub
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER