Click here to Skip to main content
15,903,856 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to check shortcut of any software on user desktop is exists or not by C# programmatically. If exists then I want to change the name of that shortcut. How to do this?

What I have tried:

I tried this code to find shortcut but it's not working. Shortcut file is exists but it displays "Shortcut File not found"

string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
string shortcutfile = desktopPath + "\\Mozilla Firefox.lnk";
if (File.Exists(shortcutfile))
{
MessageBox.Show("Shortcut File found");
}
else
{
MessageBox.Show("Shortcut File not found");
}
Posted
Updated 17-Jun-20 7:39am
v4

I just tried the code, and created a link called "Mozilla Firefox" on my desktop - it found it fine.
So check your desktop, and make sure the spelling is the same!
 
Share this answer
 
Comments
Er. Sushant Shinde 21-Mar-16 7:59am    
Is it my program correct??
OriginalGriff 21-Mar-16 8:04am    
Well...the code you show, copied into one of my apps works fine.
So you need to start looking at other factors...
first check where your .lnk file is stored for that,
Click on start button --> Run and type '%appdata%', hit enter
it will open path upto roaming folder, now search for '.lnk' path
Then you can check same folder programmatically to see if it has that shortcut
 
Share this answer
 
Check
string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonDesktopDirectory);

as it may be the shortcut in the public desktop not user desktop
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900