[Mono-list] How to get user's HOME directory

Jaroslaw Kowalski jaroslaw.kowalski@atm.com.pl
Fri, 4 Apr 2003 23:57:41 +0200

Hi All!

HOME doesn't exist on Windows, because it doesn't support a single home
directory concept (in user terms).

Instead you can have:

\Documents and Settings\All Users\Application Data - where application data
that is shared among users is stored
%USERPROFILE%\Application Data - where (roaming) application data other than
documents should be stored
%USERPROFILE%\Local Settings\Application Data - where (non-roaming)
application data other than documents should be stored
%USERPROFILE%\My Documents - where documents (*.doc, *.xsl) are generally

and others.

You shouldn't rely on a HOME or any other environment variable, because
there are more reliable ways to determine this. Windows seems to make it
harder and harder to access environment variables setup with each new
version of OS, so we should expect it to be completely disabled sometime.

Under .NET, there's System.Environment.GetSpecialFolder(). Win32 shell api
also provides a function to do it.

You use it like this:


which spits out current "My Documents" path.


----- Original Message -----
From: "Piers Haken" <piersh@friskit.com>
To: "Stefan Saring" <stefan.saring@epost.de>; "Marcus"
Cc: <mono-list@lists.ximian.com>
Sent: Friday, April 04, 2003 11:22 PM
Subject: RE: [Mono-list] How to get user's HOME directory

> -----Original Message-----
> From: Stefan Saring [mailto:stefan.saring@epost.de]
> Sent: Thursday, April 03, 2003 10:54 PM
> To: Marcus
> Cc: mono-list@lists.ximian.com
> Subject: Re: [Mono-list] How to get user's HOME directory
> Yes. On Windows2000 it's e.g. "C:\Documents and
> Settings\USERNAME\". This is the place where many
> applications store their user settings and profiles (e.g. Mozilla).

This isn't necessarily true. Firstly the directory may not be on the
'C:' drive. Secondly, the string 'Documents and Settings' can be
localized. And thirdly the subdirectory may not be the same as the
username. If for any reason the directory exists (dual-boot,
domain/local) then windows setup will pick a new name. In general, you
shouldn't make assumptions about folder names in the user's profile, you
should use the Environment.SPecialFolder enumeration instead.

Mono-list maillist  -  Mono-list@lists.ximian.com