C#/Full address of a user's Desktop
Follow-Ups to Answer from Expert Srini Nagarajan
Miguel Sierra wrote at 2007-06-19 11:06:07
I found a problem like you, but I Find a solution, maybe not the best, but this works perfectly.
The problem with this kind of paths is that they can be changed in active directory.
The solution is to find the desktop path in the registry, first we must find the localuser desktop but if this is null we will find the all users desktop registry entry. Is important to be sure that we have permision to access to that path. Here is the code:
Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine;
key = key.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders");
try
{
Desktop = key.GetValue("Desktop").ToString();
this.Mensajes.Items.Add("Se ubicó en el escritorio el " + nombrecertificado + ".PDF");
}
catch
{
Desktop = key.GetValue("Common Desktop").ToString();
this.Mensajes.Items.Add("Se ubicó en el escritorio común el " + nombrecertificado + ".PDF");
}
Try it!
Miguel Sierra Sánchez
Cic Consulting Informático
onSlaught wrote at 2007-11-13 23:10:22
Try: (C# Code)
string path = System.IO.Environment.GetFolderPath(System.Environment.SpecialFolder.DesktopDirectory)