Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resolving 'Environment.SpecialFolder.Personal' when Folder Redirection is active

Our Windows Forms application by default saves data files in a user's 'My Documents' folder (on XP) or 'Documents' folder (on Vista). We look up this location by calling:

Environment.GetFolderPath( Environment.SpecialFolder.Personal )

We know for sure this works great for users whose personal folder is on a local disk. What we're not sure about is domain users who have Folder Redirection in effect for their profile/personal data folders.

My question is: Does the above call properly resolve regardless of whether Folder Redirection is active?

I don't have the environment to test this out, and I haven't been able to find any definite confirmation one way or the other.

like image 367
CBono Avatar asked Nov 13 '08 02:11

CBono


2 Answers

Yes it does. You can test this out yourself by updating the corresponding registry entry for the folder. Look under ...

\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\
like image 162
JaredPar Avatar answered Oct 18 '22 02:10

JaredPar


I've had a user reporting the following error on an Environment.GetFolderPath(Environment.SpecialFolder.Personal) call on an XP machine whose My Documents is redirected to the network (it goes to drive O):

System.ArgumentException: Absolute path information is required.
   at System.Security.Util.StringExpressionSet.CreateListFromExpressions(String[] str, Boolean needFullPath)
   at System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList)
   at System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, String path)
   at System.Environment.GetFolderPath(SpecialFolder folder, SpecialFolderOption option)
   at System.Environment.GetFolderPath(SpecialFolder folder)

I haven't had direct access to this machine configuration yet, but from google searches and the user's help, I believe the redirect is lacking a trailing \ (eg. O: instead of O:\).

So I believe the answer would be no, it doesn't correctly resolve everytime.

like image 42
rachel Avatar answered Oct 18 '22 02:10

rachel