I have create a Wix installer project that is installing the project under C:\ProgramFiles and a desktop shortcut of the (PharmSpec.exe) is created. I want to delete this file on the desktop shortcut with some C# code. I am trying like mentioned in the post Remove desktop shortcut, but I am unable to find the file.
I tried "PharmSpec.exe.lnk", "PharmSpec.exe" and "PharmSpec.lnk" from the link above. But no matter what, I can't find that file.
Also I tried listing all the files that are on the desktop as follows, but all I see are like 3 files, desktop.ini, 2 other files and not this file. Please disregard how the code is written, I am only testing to see if I can access the PharmSpec file.
static void GetFiles()
{
string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
//string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
if (System.IO.File.Exists(Path.Combine(desktopPath, "PharmSpec.lnk")))
{
//NEVER COMES HERE
//System.IO.File.Delete(Path.Combine(desktopPath , "shortcut.lnk"));
}
DirectoryInfo d = new DirectoryInfo(desktopPath); //Assuming Test is your Folder
FileInfo[] Files = d.GetFiles("*"); //Changed search to *.exe still no use
string str = "";
foreach (FileInfo file in Files)
{
str = str + ", " + file.Name;
}
Console.Write(str);
}
Here is the screenshot of the entire desktop,
How can I delete the the shortcut file on the desktop. Please help.
Check also the public desktop folder.
Default: C:\Users\Public\Desktop