PDA

View Full Version : Resolved VB.NET Windows Service IO Issue


wldrumstcs
06-09-2010, 04:22 PM
I have a Windows service that uses System.IO to recursively retrieve files from a directory and all its subdirectories. However, when I call this function, it doesn't like the lines "Directory.GetFiles(dirPath)" and "Directory.GetDirectories(dirPath)". Any ideas why?

Thanks!

Imports System.IO
Module mdlParser
Public fileArr As New ArrayList

'* getFiles
'* - loops through the directories and subdirectories and pulls out the bloomberg files
'* parameters - dirPath: the path of the directory to start searching through
'* return val - none
Public Sub getFiles(ByVal dirPath As String)
Dim fileList() As String = Directory.GetFiles(dirPath)
Dim dirList() As String = Directory.GetDirectories(dirPath)
Dim filename As String
For Each filename In fileList
If Path.GetExtension(filename) <> ".req" Then
fileArr.Add(filename)
End If
Next

Dim dirName As String
For Each dirName In dirList
getFiles(dirName)
Next

End Sub
End Module

brad211987
06-09-2010, 06:00 PM
Define "It doesn't like"

As a guess, make sure your path is formatted properly, and make sure you have permission to read the directory you are after.

wldrumstcs
06-09-2010, 06:21 PM
Well, no errors are thrown, but that is the line it craps out on. Here's the thing... I have converted this entire program, line for line, into a regular windows application, and it works like a charm. However, it needs to be a service for our purposes, and when we make it into a service, we have all these issues.

brad211987
06-09-2010, 06:29 PM
Is the service running with the same user credentials that you tested under? I'm no expert with VB.NET but I don't see anything wrong with the code you posted, so I'm still thinking it may have something to do with permissions.

wldrumstcs
06-09-2010, 06:36 PM
I was thinking the same thing as you. However, I have all the correct permissions. I have no clue what's going on.

Mike_O
06-09-2010, 09:53 PM
Hey wldrumstcs,

Try to start your failing method from a clean slate. First, comment out everything inside it. Second, debug the windows service: put a breaking point somewhere inside the method and see what value you get from the parameter. I'm thinking that should give you some hint.

Mike

wldrumstcs
06-10-2010, 02:34 PM
I found out what the issue was. It turns out that the parameter "dirPath" was not being read correctly. Apparently, if you are using a network drive address ie something like "F:\files", you have to actually specify the real address, which in my case was "\\fileserver\data\files". For some reason, I can get away with the first format on a regular Windows application, but I have to use the second format for Windows services.

Mike_O
06-10-2010, 02:52 PM
Well, if your windows service is running on the remote machine, then it all makes sense now. Your F: is just a mapped drive, but any program running on that server has to use its real drive letter.

Mike