#

WPF, c #: get desktop as directory
 
How to get the% Desktop% directory in WPF?
 
% Desktop% belongs to the system folders and is under WPF with Environment.SpecialFolder. As a selection.
 
Here is the desktop

Environment.SpecialFolder.Desktop

 
The actual path as a string gets with Environment.GetFolderPath
 
Desktop directory as System.IO.DirectoryInfo:

//< init >
string sPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); ;
DirectoryInfo dir = new DirectoryInfo(sPath);
//</ init >

 
Here the% Desktop% path resolved in the WPF application

 
There are several special directories available for selecting special folders:

AdminTools
ApplicationData
CDBurning
CommonAdminTools
CommonApplicationData
CommonDesktopDirectory
CommonDocuments
CommonMusic
CommonOemLinks
CommonPictures
CommonProgramFiles
CommonProgramFilesX86
CommonPrograms
CommonStartMenu
CommonStartup
CommonTemplates
CommonVideos
Cookies
Desktop
DesktopDirectory
Favorites
Fonts
History
InternetCache
LocalApplicationData
LocalizedResources
MyComputer
MyDocuments
MyMusic
MyPictures
MyVideos
NetworkShortcuts
Personal
PrinterShortcuts
ProgramFiles
ProgramFilesX86
Programs
Recent
Resources
SendTo
StartMenu
Startup
System
SystemX86
Templates
UserProfile
Windows
 

 
Description at https://msdn.microsoft.com/de-de/library/system.environment.specialfolder(v=vs.110).aspx

 
C # Code example

private void Button_Click(object sender, RoutedEventArgs e)
{
//----------------< load_UserControl() >----------------
//< init >
string sPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); ;
DirectoryInfo dir = new DirectoryInfo(sPath);
//</ init >
 
//< get segments >
string sPath_Long = dir.FullName;
string[] arrPath_Segments = sPath_Long.Split(new string[] { "\\" }, StringSplitOptions.RemoveEmptyEntries);
//</ get segments >
 
foreach(string sSegment in arrPath_Segments)
{
UcPathSegment ucSegment = new UcPathSegment();
ucSegment.Caption =sSegment;
pnlBreadcrumb.Children.Add(ucSegment );
}
 

//----------------</ load_UserControl() >----------------
}

 
 
Mobile

.

0123movie.net