Hi Guys,

I have written a Windows Service which has Timer and Event Log Controls. After every 3 seconds, the service must write the list of files in a mapped directory on the network to the Event Log.

Here is the part of the code that I am trying to get working....

Private Sub Timer1_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed
Dim di As New DirectoryInfo("u:\pro\inv-reports")
' Create an array representing the files in the current directory.
Dim fi As FileInfo() = di.GetFiles()
' Print out the names of the files in the current directory.
Dim fiTemp As FileInfo
For Each fiTemp In fi
EventLog1.WriteEntry("Filename :" + fiTemp.Name)
Next fiTemp
Beep()
End Sub


The above code is supposed to print the files present in "u:\pro\inv-reports" directory to the event log (Here "u" is a mapped network drive). However, it does not work.


But the code below which access the director "c:\bin" on the local machine, works!

Private Sub Timer1_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed
Dim di As New DirectoryInfo("c:\bin")
' Create an array representing the files in the current directory.
Dim fi As FileInfo() = di.GetFiles()
' Print out the names of the files in the current directory.
Dim fiTemp As FileInfo
For Each fiTemp In fi
EventLog1.WriteEntry("Filename :" + fiTemp.Name)
Next fiTemp
Beep()
End Sub


So, I tried something else. I tried to access the network drive using a windows console application rather than a windows service. And to my surprise, it worked...
Imports System.IO

Module Module1

Sub Main()
Dim di As New DirectoryInfo("u:\pro\inv-reports")
' Create an array representing the files in the current directory.
Dim fi As FileInfo() = di.GetFiles()
Console.WriteLine("The following files exist in the print directory:")
' Print out the names of the files in the current directory.
Dim fiTemp As FileInfo
For Each fiTemp In fi
Console.WriteLine(fiTemp.Name)
Next fiTemp
Console.ReadLine()
End Sub

End Module


Can't a windows service access a network drive? I did set it up as a network service.

All suggestions/ideas are welcome

Thanks in anticipation.
Shashi