Reputation: 2337
I am trying to create-read/write a file into a subfolder of the users AppData\Roaming folder:
string fileloc = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "FolderName" + Path.AltDirectorySeparatorChar + "SomeFile.txt");
This is working brilliantly on my computer, but when I ran the program on a friend's Japanese laptop (which uses ¥ as its directory separator) they were only able to read/write to the file, and the program would crash if it needed to create the file. (I also tried the non-Alt directory separator.)
The string fileloc printed:
C:¥Users¥UserName¥Appdata¥Roaming¥FolderName/SomeFile.txt
Upvotes: 1
Views: 818
Reputation: 3250
string fileloc = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Path.Combine("FolderName", + "SomeFile.txt"));
should do what you are expecting. Does that work for you?
Upvotes: 1
Reputation: 43046
How about
string fileloc = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "FolderName"), "SomeFile.txt");
Or, perhaps easier to comprehend:
string directoryPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "FolderName");
string fileloc = Path.Combine(directoryPath, "SomeFile.txt");
Upvotes: 1