简体   繁体   中英

What is the WPF equivalent to “System.Windows.Forms.Application.X” for obtaining startup path, app data path, etc.?

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.

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?

this will help

for Application.StartupPath use AppDomain.CurrentDomain.BaseDirectory

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

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);

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM