So basically I need a string "path" to be something like:
string path = @"C:\Users\CURRENT_USER\file.txt";
How could I do that?
Sincerely,
a guy with an internet connection
Your User profile path stores in
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)
To get specifc file path from that Folder you need to combine it with hard coded string of your file name, like
string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "file.txt")
Output:
Note: Do not forget to add using System.IO
because Path
class is present in System.IO
您可以使用Environment.SpecialFolder.UserProfile
枚举。
string path=Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.