I am trying to get a path to save a file on a remote server, but I don't know how to ensure the path is within a shared directory that I have access to. This is how I was originally trying to do it:
Dim di As DirectoryInfo = New DirectoryInfo("\\ServerName\")
Dim diArr As DirectoryInfo() = di.GetDirectories()
For Each d As DirectoryInfo In diArr....
I was planning on going through the subdirectories of the server until I found one that I can write a file to, but I get this error: "The UNC path should be of the form \server\share". Is there anything I can substitute into the \share part that will exist on every server? Thank you for the help.
Edit: I enumerated the shares on the server using a ManagementObjectSearcher like this:
Dim myObjectSearcher As System.Management.ManagementObjectSearcher
Dim myScope As New ManagementScope("\\" & ServerName & "\root\CIMV2")
Dim myQuery As New SelectQuery("SELECT * FROM Win32_LogicalShareSecuritySetting")
myObjectSearcher = New System.Management.ManagementObjectSearcher(myScope, myQuery)
For Each share As ManagementBaseObject in myObjectSearcher.Get()
MessageBox.Show(share.ToString)
Next