From Environment.SpecialFolder
The system special folders are folders such as Program Files,
Programs, System, or Startup, which contain common information.
Special folders are set by default by the system, or explicitly by the
user, when installing a version of Windows.
The GetFolderPath method returns the locations associated with this
enumeration. The locations of these folders can have different values
on different operating systems, the user can change some of the
locations, and the locations are localized.
Just use
string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
files = Directory.GetFiles(path, searchPattern);
In my computer, it returns as C:\Users\Soner\Documents
Is there a way to use Environment.GetFolderPath but somehow idetifying
the correct speical folder according to the path I'm currently
checking?
Since SpecialFolder
is enum type, you can iterate their values in a loop. Here how it looks like;
public enum SpecialFolder
{
AdminTools = 0x30,
ApplicationData = 0x1a,
CDBurning = 0x3b,
CommonAdminTools = 0x2f,
CommonApplicationData = 0x23,
CommonDesktopDirectory = 0x19,
CommonDocuments = 0x2e,
CommonMusic = 0x35,
CommonOemLinks = 0x3a,
CommonPictures = 0x36,
CommonProgramFiles = 0x2b,
CommonProgramFilesX86 = 0x2c,
CommonPrograms = 0x17,
CommonStartMenu = 0x16,
CommonStartup = 0x18,
CommonTemplates = 0x2d,
CommonVideos = 0x37,
Cookies = 0x21,
Desktop = 0,
DesktopDirectory = 0x10,
Favorites = 6,
Fonts = 20,
History = 0x22,
InternetCache = 0x20,
LocalApplicationData = 0x1c,
LocalizedResources = 0x39,
MyComputer = 0x11,
MyDocuments = 5,
MyMusic = 13,
MyPictures = 0x27,
MyVideos = 14,
NetworkShortcuts = 0x13,
Personal = 5,
PrinterShortcuts = 0x1b,
ProgramFiles = 0x26,
ProgramFilesX86 = 0x2a,
Programs = 2,
Recent = 8,
Resources = 0x38,
SendTo = 9,
StartMenu = 11,
Startup = 7,
System = 0x25,
SystemX86 = 0x29,
Templates = 0x15,
UserProfile = 40,
Windows = 0x24
}