tags:

views:

69

answers:

4

I'm converting a windows forms application to a WPF application. Is there a way to obtain things like, Startup Path, User App Data Path, Common App Data Path, etc. without referencing System.Windows.Forms?

Previously, I used System.Windows.Forms.Application.StartupPath, but the System.Windows.Application.Current object doesn't contain the same information.

+4  A: 

You might want to look at System.Environment.GetFolderPath.

The values of the SpecialFolder enum are numerous:

ApplicationData
CommonApplicationData
CommonProgramFiles
Cookies
Desktop
DesktopDirectory
Favorites
History
InternetCache
LocalApplicationData
MyComputer
MyDocuments
MyMusic
MyPictures
Personal
ProgramFiles
Programs
Recent
SendTo
StartMenu
Startup
System
Templates

Is that helpful?

Dan Tao
Exactly what I needed. Thanks, everyone.
bporter
A: 

this will help

for Application.StartupPath use AppDomain.CurrentDomain.BaseDirectory

http://msdn.microsoft.com/en-us/library/system.appdomain.basedirectory.aspx

camilin87
+1  A: 

You can use the Environment class to get all types of system information. For directories, use the Environment.GetFolderPath method.

Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
mdm20
A: 

I understand and agree that referencing to System.Windows.Forms.dll looks ugly but I think that's better then decrease code re-use and re-invent bicycle instead just one more reference.

I use for example System.Windows.Forms.Application.ProductVersion in my console apps, don't like that but think that's the lesser evil..

See also this question on SO

abatishchev