0

I've got a gtk file chooser button on my application I am writing in c# using Mono Develop. I would like to set the file chooser's default location to the users' home directory regardless of what user is running it.

I've tried the ~/ short cut - fchFolder1.SetCurrentFolder("~/"); - but this did not work. I was just wondering if there was a value that the gtk file chooser used to refer to the users home directory? Thanks

Connel
  • 1,844
  • 4
  • 23
  • 36

2 Answers2

1

In C, one would use g_get_home_dir() to find the user's home directory, and set the file chooser's current location to that, but as far as I can tell, that function isn't wrapped in GTK#. Someone asked the same question on the GTK# mailing list and the answer was to use

System.Environment.GetFolderPath (SpecialFolder.Personal)
ptomato
  • 56,175
  • 13
  • 112
  • 165
0

In Unix, you can either get the HOME environment variable or use System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal).

In Windows, expand %HOMEDRIVE%%HOMEPATH% to get the "home" directory, or use the same GetFolderPath call to get the "My Documents" directory.

Discussion about the HOME and HOMEDRIVE+HOMEPATH approach: Getting the path of the home directory in C#?

Community
  • 1
  • 1
Johannes Sasongko
  • 4,178
  • 23
  • 34
  • Thanks I used the code on the link to the discussion you posted :) just in case any one else has the same problem I used the following code to make it cross platform: string homePath = (Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX) ? Environment.GetEnvironmentVariable("HOME") : Environment.ExpandEnvironmentVariables("%HOMEDRIVE%%HOMEPATH%"); – Connel Apr 14 '10 at 11:59