Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a specific location to a string in C#

Tags:

c#

How do I go about getting the info from the computers name and setting that location in a string.

Example*

string contents = File.ReadAllText(@"C:\Users\" + Settings.Default.User + "\\Documents\\My vs\\juice.txt");

Problem is, I cannot use the Setting.Default.User location because that name constantly changes.

I need that section to be some kind of variable that means the computers name.... I don't wanna just hard code in my computers name either because If I put this on my other computers then obviously the name would change

like image 655
user3720747 Avatar asked Dec 06 '22 23:12

user3720747


1 Answers

you are looking for Environment class:

you can use Environment.MachineName Property

Anyway if you need a special folder path you can use: Environment.GetFolderPath

there you can find all the special folder available Environment.SpecialFolder Enumeration

like image 183
giammin Avatar answered Dec 18 '22 13:12

giammin