i could not edit or comment on the answer from Sellorio so i made a new answer:
public static string[] GetDirectoriesInNetworkLocation(string networkLocationRootPath)
{
Process cmd = new Process();
cmd.StartInfo.FileName = "cmd.exe";
cmd.StartInfo.RedirectStandardInput = true;
cmd.StartInfo.RedirectStandardOutput = true;
cmd.StartInfo.CreateNoWindow = true;
cmd.StartInfo.UseShellExecute = false;
cmd.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
cmd.Start();
cmd.StandardInput.WriteLine($"net view {networkLocationRootPath}");
cmd.StandardInput.Flush();
cmd.StandardInput.Close();
string output = cmd.StandardOutput.ReadToEnd();
cmd.WaitForExit();
cmd.Close();
output = output.Substring(output.LastIndexOf('-') + 2);
output = output.Substring(0, output.IndexOf("The command completed successfully."));
return
output
.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)
.Select(x => System.IO.Path.Combine(networkLocationRootPath, x.Substring(0, x.IndexOf(' '))))
.ToArray();
}
if your executation path has a '-' in it, you will recive a zero length error at line:
output = output.Substring(output.LastIndexOf('-') + 2);
fix this by removing the path first:
string CurrentExecutePath = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
output = output.Replace(CurrentExecutePath, "");
output = output.Substring(output.LastIndexOf('-') + 2);