Is there a .Net way to get "Shared Documents" path?

I know of Environment.SpecialFolder which can return many paths, but it doesn't have a method for returning "Shared Documents","Shared Pictures", "Shared Video" or "Shared Music". Is there a way to return these paths without hard-coding them

Thanks!



Answer this question

Is there a .Net way to get "Shared Documents" path?

  • Salanitro

    Dear BenjStarratt,

    Thanks for your interest in .Net Framework. Having completely researched on your raised question, there can be an alternative for you to retrieve the path of shared documents:

    1. Principle: retrieve the physical paths of those folders from registry key:

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders

    Under the key, here are some values:

    "Common Documents" corresponds to Shared Documents

    "CommonMusic" corresponds to Shared Music

    "CommonPictures" corresponds to Shared Pictures

    "CommonVideo" corresponds to Shared Video

    2. A snapshot of sample code:

    using Microsoft.Win32;

    RegistryKey key = Registry.LocalMachine.OpenSubKey(
    @"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" );

    // Shared Documents folder path
    // By default C: disk-based OS installation,
    // You might get "C:\Documents and Settings\All Users\Documents"
    object shrdoc = Registry.GetValue( key.Name, "Common Documents", "No Shared Documents Got!" );

    // Shared Music folder path
    // You might get "C:\Documents and Settings\All Users\Documents\My Music"
    // Here, "My Music" is the real name of the folder "Shared Music", where "Shared Music"
    // is only the alias of "My Music" and can't be retrieved.
    object shrmus = Registry.GetValue( key.Name, "CommonMusic", "No shared Music Got!");

    // Shared Pictures folder path
    // You might get "C:\Documents and Settings\All Users\Documents\My Pictures"
    // Here, "My Pictures" is the real name of the folder "Shared Pictures", where "Shared Pictures"
    // is only the alias of "My Pictures" and can't be retrieved.
    object shrpic = Registry.GetValue(key.Name, "CommonPictures", "No Shared Pictures Got!");

    // Shared Video folder path
    // You might get "C:\Documents and Settings\All Users\Documents\My Video"
    // Here, "My Video" is the real name of the folder "Shared Video", where "Shared Video"
    // is only the alias of "My Video" and can't be retrieved.
    object shrvdo = Registry.GetValue( key.Name, "CommonVideo", "No shared Video Got!");

    Please try the above steps and feel free to ask if any questions.

    Sincerely hope it can be of any help to you.

    Best regards,

    Cleo



  • Is there a .Net way to get "Shared Documents" path?