Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 916
Xceptionist Avatar asked Sep 07 '14 01:09

Xceptionist


People also ask

What is Roaming folder in C drive?

Where “Roaming” is a sub folder of “AppData”. Into that folder might be placed things like default templates, configuration files, and other support data that applications might use that a) might be different for other users of the machine, and b) aren't your actual working documents.

How do I get to Roaming folder in Windows 10?

The quick and easy way is to click Start, or the Cortana search icon in Windows 10, type %appdata% , and select the top search result, which should take you to AppData > Roaming.

What is stored in AppData Roaming?

AppData is a hidden folder located in C:\Users\<username>\AppData. The AppData folder contains custom settings and other information needed by applications. For example, you might find the following in your AppData folder: Web browser bookmarks and cache.


1 Answers

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"
);
like image 160
AlexD Avatar answered Oct 06 '22 00:10

AlexD