#

WPF, c#: Desktop als Verzeichnis erhalten
 
Wie bekommt man das Verzeichnis %Desktop% in WPF ?
 
%Desktop% gehört zu den Systemordnern und wird unter WPF mit Environment.SpecialFolder. als Auswahl aufgelistet.
 
Hier der Desktop

Environment.SpecialFolder.Desktop

 
Den eigentlichen Pfad als String bekommt mit Environment.GetFolderPath
 
Desktop-Verzeichnis als System.IO.DirectoryInfo:

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

 
Hier der Pfad %Desktop% in der WPF Anwendung aufgelöst

 
Als Auswahl der Spezialfolder stehen mehrere spezielle Verzeichnisse zur Verfügung:

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
 

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

 
C# Codebeispiel

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

.

123movies