Problems with FileInfo
I'm an italian user and I've these directories:
- Utenti (as Users)
- Immagini (as Pictures)
- Etc..
Now, when I search a file with Windows SDK DSearch API, I 开发者_JS百科get this path:
C:\Utenti\\myfile.txt
and when I invoke:
FileInfo file = new FileInfo(@"C:\Utenti\<User>\myfile.txt");
the field file.Length throws an exception (FileNotFound). But if I use:
FileInfo file = new FileInfo(@"C:\Users\<User>\myfile.txt");
file.Length works correctly.
How I can solve this issue?
Use Environment.GetFolderPath(Environment.SpecialFolder....));
to retrieve the folder you need.
If you get from somewhere else a localized path, you can try to match with the actual special folder localized to by looking at this question: How to get the actual (localized) folder names? Basically this tour out in using ( interop ) the SHGetLocalizedName function.
Well known folder and file names are only localized at the UI level. You have to access them via their correct names from code.
Maybe the Environment.SpecialFolder
enum helps you out.
精彩评论