Developer should not use "Hide extensions for known file types" in Windows Explorer

One my colleague got a new PC and had a problem opening file using simple code(just from MSDN example ):
 
FileInfo fi1 = new FileInfo(relativePath);

        if (!fi1.Exists)
....
It showed that file doesn't exist. We've tried also File.Exists(relativePath), changed the path to absolule- the same result-
file is visible in Windows Explorer, but doesn't exist in code. Note that directory was shown in debugger as existing.
We've created(using Windows Explorer) a new Text file, named "test.txt" and tried to open it in code- the same "file not exist" problem.
We've checked different security settings- the same.
Finally I recognized, that  Windows Explorer was set to "Hide extensions for known file types" and file visible as "test.txt" was actually created as
test.txt.txt.
The lesson: developer (and any user who has understanding of file extensions) should never have "Hide extensions for known file types" in Windows Explorer.
By the way: If you want to use a relative path from Windows Service, reset current directory  in the code
System.IO.Directory.SetCurrentDirectory (System.AppDomain.CurrentDomain.BaseDirectory);

posted @ Thursday, August 14, 2008 12:22 AM

Print

Comments on this entry:

# re: Developer should not use "Hide extensions for known file types" in Windows Explorer

Left by Marcel Wijnands at 8/14/2008 2:15 AM
Gravatar
that is actually one of the first settings I change after installing Windows.

# re: Developer should not use "Hide extensions for known file types" in Windows Explorer

Left by Richard at 8/26/2008 4:35 AM
Gravatar
We have this same problem using VFP9. So how to you test for "Hide extensions..." being checked?

# re: Developer should not use "Hide extensions for known file types" in Windows Explorer

Left by Michael Freidgeim at 8/26/2008 9:53 AM
Gravatar
Richard,
We just unticked it MANUALLY in Windows Explorer.

Your comment:



 (will not be displayed)


 
 
 
Please add 7 and 1 and type the answer here:
 

Live Comment Preview:

 
«December»
SunMonTueWedThuFriSat
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910