user3896290
user3896290

Reputation:

How do you locate a folder inside of Roaming using C#?

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

Answers (2)

Raj
Raj

Reputation: 29

string appDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
string filePath = Path.Combine(appDataFolder + "\\SubfolderName\\" + "filename.txt");

Upvotes: -1

AlexD
AlexD

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

Related Questions