2

Possible Duplicate:
How can i get the path of the current user’s “Application Data” folder?
Windows XP Application Data Folder?

I have to save some settings in application data but, when i use something as "@C:\Documents ..." someone can run windous on D:\ So how to get that directory ??

Community
  • 1
  • 1
mtmtt
  • 33
  • 1
  • 1
  • 4
  • And [this post](http://stackoverflow.com/questions/703281/getting-path-relative-to-the-current-working-directory) as well. – Brian Jan 09 '13 at 19:44

3 Answers3

16

You can use Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); ...

And there's exaple, how you can use it:

string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

and it returns something like C:\\Users\\UserName\\ApplicationData

and you can use Environment.SpecialFolder.Desktop too so you can get to desktop of actual user...

GemHunter1
  • 441
  • 1
  • 4
  • 15
0

see the code at the end of this: http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx

jlew
  • 10,491
  • 1
  • 35
  • 58
0

Look at this MSDN entry to get the application data directory, Environment.SpecialFolder.

What I used to do is use Evironment.SystemDirectory and then break that down depending on what I need. But if you are worried about the drives then use the DriveInfo class by doing DriveInfo.GetDrives()

Austin Henley
  • 4,625
  • 13
  • 45
  • 80