List all shared folders from a network location

I know this thread is old, but this solution might eventually help someone. I used a command line then returned a substring from its output containing the directory names.

    static void Main(string[] args)
    {
        string servername = "my_test_server";
        List<string> dirlist = getDirectories(servername);
        foreach (var dir in dirlist)
        {
            Console.WriteLine(dir.ToString());
        }      
        Console.ReadLine();
    }

    public static List<string> getDirectories (string servername)
    {
        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 \\\\" + servername);
        cmd.StandardInput.Flush();
        cmd.StandardInput.Close();
        string output = cmd.StandardOutput.ReadToEnd();
        cmd.WaitForExit();
        cmd.Close();
        List<string> dirlist = new List<string>();
        if(output.Contains("Disk"))
        {
            int firstindex = output.LastIndexOf("-") + 1;
            int lastindex = output.LastIndexOf("Disk");
            string substring = ((output.Substring(firstindex, lastindex - firstindex)).Replace("Disk", string.Empty).Trim());
            dirlist = substring.Split('\n').ToList();
        }
        return dirlist;
    }