用于获取启动路径,应用程序数据路径等的WPF等效于"System.Windows.Forms.Application.X"是什么?

bpo*_*ter 17 c# wpf

我正在将Windows窗体应用程序转换为WPF应用程序.有没有办法获取诸如启动路径,用户应用程序数据路径,通用应用程序数据路径等,而无需引用System.Windows.Forms?

以前,我用过System.Windows.Forms.Application.StartupPath,但System.Windows.Application.Current对象不包含相同的信息.

Dan*_*Tao 14

你可能想看一下System.Environment.GetFolderPath.

SpecialFolder枚举的价值很多:

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

这有用吗?


Cam*_*hez 6

这会有所帮助

对于Application.StartupPath,请使用AppDomain.CurrentDomain.BaseDirectory

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

  • 考虑到OP的例子是关于StartupPath,我相信这应该是公认的答案.SpecialFolder.Startup是*完全*不同的东西. (2认同)