Bug 41258 - Environment.SpecialFolder.MyDocuments is wrong on OS X
Summary: Environment.SpecialFolder.MyDocuments is wrong on OS X
Status: CONFIRMED
Alias: None
Product: Class Libraries
Classification: Mono
Component: mscorlib (show other bugs)
Version: unspecified
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Future Release
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-05-23 16:22 UTC by Norbert Virth
Modified: 2017-10-12 12:25 UTC (History)
8 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Version info provided by Xamarin Studio (974 bytes, text/plain)
2016-05-23 16:22 UTC, Norbert Virth
Details

Description Norbert Virth 2016-05-23 16:22:29 UTC
Created attachment 16073 [details]
Version info provided by Xamarin Studio

This code:

    var myDocumentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

will return the same as if called with Environment.SpecialFolder.UserProfile on OS X
So "/Users/username", instead of "/Users/username/Documents" (on a mac with language EN)
Comment 1 Chris Hamons 2016-05-23 16:52:33 UTC
The code in question is here:

https://github.com/mono/mono/blob/master/mcs/class/corlib/System/Environment.cs#L619
Comment 2 Marek Safar 2016-05-25 07:50:21 UTC
This is by design.

Unfortunately SpecialFolder.Personal has same value as SpecialFolder.MyDocuments so we cannot easily distinguish between them hence we return /Users/username which sort of fits to both of them.
Comment 3 Norbert Virth 2016-05-25 09:19:02 UTC
A workaround then. The link below is for iOS, but it worked for me on OS X 10.10 as well:

http://stackoverflow.com/a/28663420/2080504

And the code based on the link which makes it:

var myDocumentsDir = NSFileManager.DefaultManager.GetUrls(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomain.User)[0].Path;
Comment 4 Aaron Bockover [MSFT] 2016-05-26 03:32:58 UTC
Norbert is correct. We are treating Personal and MyDocument the same as UserProfile.

From the RS definition of SpecialFolder:

  UserProfile = Win32Native.CSIDL_PROFILE
  Personal = Win32Native.CSIDL_PERSONAL
  MyDocuments = Win32Native.CSIDL_PERSONAL

And if we look at the CSIDL definitions:

  CSIDL_PROFILE:  The user's profile folder. A typical path is C:\Users\username.
  CSIDL_PERSONAL: The virtual folder that represents the My Documents desktop item. This is equivalent to CSIDL_MYDOCUMENTS. A typical path is C:\Documents and Settings\username\My Documents.

So yes, Personal and MyDocuments are the same, but we've been treating Personal as UserProfile, which is a bug in Mono on Mac.

So on a Mac it should be (and if not the paths below, whatever blessed NSFileManager API makes sense, as Norbert points out):

  UserProfile → $HOME
  Personal → $HOME/Documents
  MyDocuments → $HOME/Documents
Comment 6 Marek Safar 2017-10-12 12:25:18 UTC
We could try to change Personal/MyDocuments case with some fall-back option to old behaviour

Note You need to log in before you can comment on or make changes to this bug.