File.Exists()

R

repairman2003

I'm trying to check whether a .lnk (LNK - Windows shortcut file)
exists. I can successfully create the lnk file and then go browse to
the folder and see the lnk file is there, but calling
File.Exists("test.lnk") fails. How can I do this?
 
M

Mattias Sjögren

I'm trying to check whether a .lnk (LNK - Windows shortcut file)
exists. I can successfully create the lnk file and then go browse to
the folder and see the lnk file is there, but calling
File.Exists("test.lnk") fails. How can I do this?

Have you tried specifying the fully qualified file path?


Mattias
 
R

repairman2003

Have you tried specifying the fully qualified file path?

Mattias

yeah. I used Directory.SetCurrentDirectory() to set the path so I
wouldn't have to type in the full path. But not running that and just
inserting the full path still results in the same failure.
 
S

Sheng Jiang[MVP]

use Path.Combine to create a absolute path

--
Sheng Jiang
Microsoft MVP in VC++
Have you tried specifying the fully qualified file path?

Mattias

yeah. I used Directory.SetCurrentDirectory() to set the path so I
wouldn't have to type in the full path. But not running that and just
inserting the full path still results in the same failure.
 
R

repairman2003

That's not the problem. The problem is the File.Exists() returns
false no matter what if it is a .lnk file. I even created one in c:\
and called File.Exists("c:\\test.lnk") and it still returns false.
 
R

repairman2003

Ok, after much headache, my boss found that windows hides the file
extension for .lnk files no matter what. So File.Exists("c:\
\test.lnk.lnk") returns true.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top