在WPF

2012-04-19 96 views
1

在我的项目中删除硬编码的文件夹路径,我指的是一个文件夹:在WPF

string path=Path.Combine(@"E:\Per\kamlendra.sharma\Windows\main\software\my.software\my.software.Server\Resources", string.Format("LocalizationDictionary.{0}.xaml", SelectedNewLanguage.culture)); 

但我不想硬编码这个地址:

@"E:\Per\kamlendra.sharma\Windows\main\software\my.software\my.software.Server\Resources"

谁能请建议更好的方法?

+1

你想获得应用程序的路径都IO.Path.GetDirectoryName(Application.ExecutablePath)? – Cynede 2012-04-19 06:03:01

+0

你想使用最终的路径? – 2012-04-19 06:08:31

回答

1

可以得到当前正在执行的组件的UNC路径。然后,您可以以此为基础来访问特定的子文件夹 - 这是假设你正在寻找的文件夹,其中的组件位于一个子文件夹...

System.Reflection.Assembly.GetExecutingAssembly().Location //This actually returns the assembly file name, so you would need to use FileInfo to get the folder location. 

一个更好的方法可能是系统。 AppDomain,它使您可以访问实际WPF应用程序的位置而不是程序集。

System.AppDomain.CurrentDomain.BaseDirectory