10-23-2008 08:19 AM
I have written a plugin that reads an xml file to gather some user defined properties. I locate the xml file with the following line:
string strConfigDataFile = Path.Combine(Environment.CurrentDirectory, @"Plugins\ConfigData.xml");
This works fine as long as ACT is started from it's normal location e.g. C:\Program Files\ACT\Act for Windows.
However, we have a client that is starting ACT! by placing the PAD file on the desktop, and double clicking of the PAD file. When it starts this way the plugin creates an exception that the file cannot be found. Upon further investigation, Environment.CurrentDirectory is returning "C:\Documents and Settings\My User\Desktop", which is where the PAD file lives.
I could place the config file anywhere, such as the system folder and that should resolve the issue.
My question is this. Obviously ACT! is able to determine the Plugins folder regardless of how ACT! is started. How can I capture this path?
11-07-2008 08:00 AM
Another option is to use:
System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly(); string path = asm.Location + ".config";
If your plugin is named "MyPlugin.dll" then this results in a full path to a config file named "<Plugin Path>\MyPlugin.dll.config". There are a few other options for getting different assemblies. I actually use GetAssembly( this.GetType() ), but I believe that GetExecutingAssembly( ) should accomplish the same thing.