-2

So I have been making an application where I edit a .txt file that I would like to send to other people, but it has my directory in it. It is basically C:\users\(MYNAME)\etc... and the application wouldn't work for anyone except me. Anyone have a solution on that.

My code is:

string text = File.ReadAllText(@"C:\Users\ME\XXX\XXX\XXX\options.txt");
text = text.Replace("text", "text");
File.WriteAllText(@"C:\Users\ME\XXX\XXX\.XXX\options.txt", text);
grrigore
  • 1,050
  • 1
  • 21
  • 39
Marcin
  • 1
  • 2
    So don't use the `Users` directory? As you can probably tell by name, each user will have their own. Somewhere else in C:\ is probably what you want. – Broots Waymb Nov 19 '18 at 21:40
  • Yes, so what would I need to use instead of 'users'? I have tried many things and none worked. – Marcin Nov 19 '18 at 21:42
  • 1
    Pretty much anything else above `Users`... You have the entire C: drive at your disposal. It really depends on where you want to put it. If it's something related to your particular app, `%programdata%` might be a good place to start. – Broots Waymb Nov 19 '18 at 21:45
  • Possible duplicate of [How to reference the C:\Users\Public directory programmatically in C#](https://stackoverflow.com/questions/4649810/how-to-reference-the-c-users-public-directory-programmatically-in-c-sharp) – mjwills Nov 19 '18 at 21:50

1 Answers1

2

Either use a different directory like Broots recommended or you can get the current user's folder with:

Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)

Which will return C:\Users\Username

Nathan Champion
  • 1,291
  • 1
  • 14
  • 23