Environment.GetFolderPath (Environment.SpecialFolders.ApplicationData) returns C:

I encountered a very strange behavior on the computer of one of my clients, and I can’t understand why this happens: When the application calls the Environment.GetFolderPath(Environment.SpecialFolders.ApplicationData) return value will be C:.

This, of course, is wrong, its AppData directory is normal C:\Users\.....\AppData\Roaming, and its variable also %APPDATA%points to this directory.

Can anyone shed some light on why this might happen?

EDIT: Code ...

LogFilePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\ReportsAddin";
if (!Directory.Exists(LogFilePath) && Properties.Settings.Default.Logging == true)
{
    try
    {
        Directory.CreateDirectory(LogFilePath);
    }
    catch (Exception ex)
    {
        // ...
    }
}

The exception thrown says that it cannot create a directory consisting of empty lines or spaces. A study with some result showed that the AppData folder that comes back from this call is C: when in fact it should be the user's real AppData folder.

+4
1

, Environment.SpecialFolder.ApplicationData, ( ).

, , ApplicationData. , , , .

Environment.SpecialFolder.ApplicationData Environment.SpecialFolder.CommonProgramFiles Environment.SpecialFolder.CommonProgramFilesX86.

+1

All Articles