0

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

  • 1
    Possible duplicate of [How can I get the current user directory?](https://stackoverflow.com/questions/1140383/how-can-i-get-the-current-user-directory) – Avi Meltser Jun 01 '19 at 07:07

2 Answers2

3

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:

enter image description here

Note: Do not forget to add using System.IO because Path class is present in System.IO

Prasad Telkikar
  • 15,207
  • 5
  • 21
  • 44
2

You can use the Environment.SpecialFolder.UserProfile enumeration.

string path=Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
bolkay
  • 1,881
  • 9
  • 20