Reputation: 717
In my project I am referring to a folder:
string path=Path.Combine(@"E:\Per\kamlendra.sharma\Windows\main\software\my.software\my.software.Server\Resources", string.Format("LocalizationDictionary.{0}.xaml", SelectedNewLanguage.culture));
But I don't want to hard code this address:
@"E:\Per\kamlendra.sharma\Windows\main\software\my.software\my.software.Server\Resources"
Can anyone please suggest a better approach?
Upvotes: 1
Views: 835
Reputation: 391
The UNC path of the currently executing assembly can be obtained. You can then use this as the basis to access the specific subfolder - this is assuming the folder you are looking for is the a subfolder of where the assembly is located...
System.Reflection.Assembly.GetExecutingAssembly().Location //This actually returns the assembly file name, so you would need to use FileInfo to get the folder location.
A better approach is probably System.Appdomain, which gives you access to the location of the actuall WPF application rather than the assembly.
System.AppDomain.CurrentDomain.BaseDirectory
Upvotes: 1