none
appending sub-folders to 'Environment.SpecialFolder'... RRS feed

  • Question

  • Hi all, I need to add a sub-folder to the existing Environment.SpecialFolder path.
    For example, I have a public property in my app something along the lines of

    public Environment.SpecialFolder mySpecialFolder;

    I need to initialize this variable with something like,

    mySpecialFolder = System.Environment.SpecialFolder.MyDocuments + @"\sub-folder1\sub-folder2";

    but I'm getting an error complaining that string cannot be converted into a special folder..that make sense..but is there anyway I could set this property the way I want?

    Appreciate your comments/suggestions.

    Regards,
    Monday, July 20, 2009 7:38 AM

Answers

  • System.IO.Directory.CreateDirectory(Path.Combine(System.Environment.SpecialFolder.MyDocuments, @"sub-folder1\sub-folder2"));
    You can just create a folder as a subfolder of the special folder. You cannot add it to special folders list because that would not make any sense since special folders are folders that all applications know. If you create a new folder, other applications won't recognize it anyway, so why bother?

    The above is what you need to do to create a directory.

    Please remember to mark the replies as answers if they answered your question :)
    • Marked as answer by liurong luo Wednesday, July 22, 2009 9:22 AM
    Monday, July 20, 2009 7:48 AM

All replies

  • System.IO.Directory.CreateDirectory(Path.Combine(System.Environment.SpecialFolder.MyDocuments, @"sub-folder1\sub-folder2"));
    You can just create a folder as a subfolder of the special folder. You cannot add it to special folders list because that would not make any sense since special folders are folders that all applications know. If you create a new folder, other applications won't recognize it anyway, so why bother?

    The above is what you need to do to create a directory.

    Please remember to mark the replies as answers if they answered your question :)
    • Marked as answer by liurong luo Wednesday, July 22, 2009 9:22 AM
    Monday, July 20, 2009 7:48 AM
  • one question though, I've already have those sub-folders, and other parts of the application are using these folders, so by creating a new sub-folders would wipe out the data that is used by other parts..

    essentially, what I'm trying to achieve is, I have a folderselection control something like (FolderBrowserDialog) and I need to set its default location to
    System.Environment.SpecialFolder.MyDocuments + @"\sub-folder1\sub-folder2"

    I guess, I didn't ask the question right..apologies..


    Monday, July 20, 2009 7:58 AM
  • Hi,

    "I've already have those sub-folders, ..."
    Why not checking if the folder is existed already by using:
       System.IO.Directory.Exists()

    Best regards,
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have any feedback, please tell us.
    Welcome to the All-In-One Code Framework!
    Wednesday, July 22, 2009 9:24 AM