C#C
C#3y ago
7 replies
⚔ Notion ⚔

Creating Directories for Users

So I want to create a directory when the form loads. But, the issue I'm going to have if another person uses said program is that their computer name is not going to be the same. I searched on the website [ https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/file-system/how-to-create-a-file-or-folder ] stuff but I couldn't find anything related to creating a directory on a general computer..

Code I have:
private void Form1_Load(object sender, EventArgs e)
{
    // A method for setting the colors and other settings.
    ColorAndSettings();

    // The path of the directory I want to create.
    string path = "C:\\Users\\Jay\\Documents\\FileEditor\\Saves";

    // A check to see if the directory does not exist.
    if (!Directory.Exists(path)) {
        // If it don't exist the create the directory at targeted path, set above.
        Directory.CreateDirectory(path);
    }
}


And lets say you used it and your computer name was "Johnny" or something it obviously wouldn't work.. And that's what I need help with.. Any info where I can read about this or can someone just explain how to do such?
Was this page helpful?