Kamlendra Sharma
Kamlendra Sharma

Reputation: 717

Remove Hardcoded Folder Path in WPF

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

Answers (3)

killspice
killspice

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

Damith
Damith

Reputation: 63065

This is how to configure and use application data files.

Upvotes: 0

TheRealTy
TheRealTy

Reputation: 2429

You can store application data in app.config

Upvotes: 4

Related Questions