How to set specific location for string in C #

How can I get information on behalf of computers and set this location on a line.

Example *

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

The problem is that I cannot use the Setting.Default.User location because this name is constantly changing.

I need this section to be some kind of variable that means the name of the computer ... I donโ€™t want to just write code on my computer, because if I put it on other computers, then obviously the name will change

+4
source share
4 answers

Environment.GetFolderPath, :

var folder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
var path = System.IO.Path.Combine(folder, "My vs\\juice.txt");
string contents = File.ReadAllText(path);
+6

You are looking for ... Environment.MachineName

+1
source

You want to use Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments) as described here http://msdn.microsoft.com/en-us/library/system.environment.specialfolder(v=vs.110).aspx

0
source

Source: https://habr.com/ru/post/1568310/


All Articles