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:
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?
6 Replies
open a command prompt and run
set
to quickly get a list of all environment variables
you can use the userprofile
variable instead of hardcoding C:\Users\Jay
Environment.GetEnvironmentVariable Method (System)
Retrieves the value of an environment variable.
Thank you, I will look into this. If I cannot get it working I'll report back with my issue and updated code.
a good idea is to also use Path.Combine or Path.Join (depends what the inputs can be)
to make this cross-platform, you'd need to choose an environment variable name based on the current OS, https://en.wikipedia.org/wiki/Environment_variable#True_environment_variables
Environment variable
An environment variable is a dynamic-named value that can affect the way running processes will behave on a computer. Environment variables are part of the environment in which a process runs. For example, a running process can query the value of the TEMP environment variable to discover a suitable location to store temporary files, or the HOME ...
OperatingSystem Class (System)
Represents information about an operating system, such as the version and platform identifier. This class cannot be inherited.
I will look into this also.