0

I have the following piece of C# .NET 4 code that lists out files that are part of the "All Users" desktop that are displayed on the current users desktop:

foreach (String desktopFilePath in Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.CommonDesktopDirectory)))
{
    Console.WriteLine(desktopFilePath);
}

For instance:

C:\Documents and Settings\All Users\Desktop\SomeShortcut.lnk

Note that I am using the example of a shortcut, but I would expect this to be the same for any other type of file.

What I want to do is mimic the current user deleting this file from their desktop (it will show up again once they logout and back in).

I had expected to see this file listed when using SpecialFolder.Desktop because this should refer to the logical Desktop rather than the physicial desktop, but this is not the case.

For instance, this does not list the above file:

Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.Desktop))

So, how do I delete the "logical" version of this file?

jzacharuk
  • 2,058
  • 1
  • 16
  • 22
  • what about Environment.SpecialFolder.CommonDesktopDirectory?? – Adam Jan 06 '12 at 22:12
  • If I delete the file from Environment.SpecialFolder.CommonDesktopDirectory then it deletes it from the All Users directory and does not follow the **bolded** statement above. – jzacharuk Jan 06 '12 at 22:19

0 Answers0