Reputation:
I'm trying to figure out a way to navigate to a sub folder in Roaming using C#. I know to access the folder I can use:
string folder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
What I'm trying to do is navigate to a folder inside of Roaming, but do not know how. I basically need to do something like this:
string insideroaming = string folder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData\FolderName);
Any way to do this? Thanks.
Upvotes: 6
Views: 2178
Reputation: 29
string appDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
string filePath = Path.Combine(appDataFolder + "\\SubfolderName\\" + "filename.txt");
Upvotes: -1
Reputation: 32566
Consider Path.Combine:
string dir = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"FolderName"
);
It returns something similar to:
C:\Users\<UserName>\AppData\Roaming\FolderName
If you need to get a file path inside the folder, you may try
string filePath = Path.Combine(
dir,
"File.txt"
);
or just
string filePath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"FolderName",
"File.txt"
);
Upvotes: 8