I have a config file that I need to load as part of the execution of a dll I am writing.
The problem I am having is that the place I put the dll and config file is not the "current location" when the app is running.
For example, I put the dll and xml file here:
D:\Program Files\Microsoft Team Foundation Server 2010\Application Tier\Web Services\bin\Plugins
XDocument doc = XDocument.Load(@".\AggregatorItems.xml")
XDocument doc = XDocument.Load(CoolDLLClass.CurrentDirectory+@"\AggregatorItems.xml")
You are looking for
string assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string xmlFileName = Path.Combine(assemblyFolder,"AggregatorItems.xml");
Location property does not work correctly under some conditions (testing using NUnit, TFS instantiated DLL, Outlook?) - in that case you can use the