1
I need to verify the existence of a shortcut on the desktop of the computer, but the code below does not leave the if (!File.Exists(pasta))
private void Instalando()
{
string pasta = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\estoque Box - Gerenciamento de estoque.Lnk";
if (!File.Exists(pasta))
{
MessageBox.Show(pasta);
pnInstalando.Visible = true;
pnInstalando.Enabled = true;
}
else if (File.Exists(pasta))
{
MessageBox.Show("Olá");
pbInstalando.Visible = false;
pbInstalando.Enabled = false;
pBarInstalando.Visible = false;
pBarInstalando.Enabled = false;
pbInstalado.Visible = true;
btFechar.Enabled = true;
btFechar.Visible = true;
}
}
The shortcut, even existing in the code it accuses non-existence of the shortcut. Someone can help me?
Not only are you looking at the file extension on the desktop?
– Jéf Bueno
The extension . Lnk is specific to shortcuts, the path is OK and the file is there, I do not know what is happening!
– Marlon Pereira
I know. What is the value of
pasta? I mean, exactly, what is the value of the string? Take it by debug, or print it on the console and paste it here,– Jéf Bueno
C:\Users\Marlon Pereira\Desktop\estoque Box - Gerenciamento de estoque.Lnk– Marlon Pereira
Are you sure this
.lnkis not duplicated in the file name?– Jéf Bueno
Note that the extension usually gets hidden in Windows, so if you’re seeing a . lnk it’s very likely that it’s duplicated.
– Jéf Bueno
It worked, thank you!
– Marlon Pereira
Choose the young man’s answer as correct.
– Jéf Bueno