Network Share closes isn't open?

vinnie881

Well-known member
Joined
Sep 3, 2006
Messages
152
Programming Experience
3-5
I am using the following line of code to grab directories off of a network share

system.IO.Directory.GetDirectories("\\Myserver\Datawarehouse\")

This works fine as long as that share has been accessed recently, if it hasn't the machine temporarly closes that connection, causing me to get a exception. The funny thing is that the command above does open the connection back up, but it's post the exception, which does me no good.

Is there something I can do to force this connection to re-open prior to running that command?

Thanks
 
One way is to catch the exception and re-try. Or perhaps do a DirectoryExists() and that may re-open the connection. Or map a network drive, as Windows then takes care of all that behind-the-scenes stuff.
 
google for mpr.dll WNetRestoreConnectionW VB.NET - its the api call to restore network drives. Call it before attempting to use the drive
 
Back
Top