tags:

views:

1678

answers:

2

As i understand it, you're supposed to use Environment.GetFolderPath method so you have OS independent code...

WinXP uses C:\Docs and Settings\ Vista uses C:\ProgramData and c:\Users

I'm using the code below on a vista computer and it's returning a c:\documents and settings directory instead of c:\ProgramData like it should... Any ideas?

        string commonAppData = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
        try
        {
            File.CreateText( Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\mycompany\\uid");
            log.Debug("Created file successfully");
        }
        catch (Exception ex)
        {
            log.Error("Unable to create the uid file: ", ex);
        }

EDIT: I was mistaken... See my answer below. Please vote to close this post as it's no longer relevent.

+10  A: 
blak3r
+1: This is actually a pretty good reference. I come back to it from time to time to see how XP and Win7 PCs treat folders.
jp2code
+1  A: 

+1 useful!

Output on Ubuntu 9.10:

SpecialFolder.ApplicationData: /home/$USER/.config
SpecialFolder.CommonApplicationData: /usr/share
SpecialFolder.ProgramFiles: 
SpecialFolder.DesktopDirectory: /home/$USER/Desktop
SpecialFolder.LocalApplicationData: /home/$USER/.local/share
SpecialFolder.MyDocuments: /home/$USER
SpecialFolder.System: 

SpecialFolder.Personal: /home/$USER

where $USER is the current user

Tom