Using C#, how can I delete a shortcut from a user's desktop?
Tried this with no success:
string WinUser = WindowsIdentity.GetCurrent().Name;
WinUser = WinUser.Substring(WinUser.LastIndexOf("\\") + 1);
File.Delete("C:\\Users\\" + WinUser + "\\Desktop\\Touch Data.lnk");
What am I missing? Appreciate any advice on this!
Universal desktop program icon/shortcuts are located in C:\Users\Public\Desktop. To work around this, go into C:\Users\Public\Desktop and delete all the program icons.
First, I would suggest you to try deleting the shortcut by pressing delete key on keyboard, after clicking the desktop shortcut which you want to delete. Check if you are able to delete. Method 2: Check if you are able to delete these desktop shortcuts in safe mode.
Try the following:
string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
File.Delete(Path.Combine(desktopPath, "Touch Data.lnk"));
I had this issue in this question I asked:
Why does FolderBrowserDialog not allow the desktop as SelectedPath when RootFolder is MyComputer?
The answer I got was this:
Apparently, the Desktop in Win 7 doesn't actually exist at the path
c:\Users\username\Desktop
The system pretends it does at the command prompt and in windows explorer. But since it isn't there, the part of SelectedPath that requires its path to be under RootFolder disallows setting the path in that way.
It's possible this is the issue. You should use the Environment.GetFolderPath function to get a handle on the real desktop. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With