The problem is that the DLL is moved to another folder, away from the bin directory. Since you don't know the physical path to the Bin directory, you can't access the INI file which is stored there.
Since hard coding the parameters inside the DLL is not a solution I had to find something else. The solution I came up with was to store this information in the Web.config file along with other FluorineFX settings.
How to store your own data inside Web.config file is described on the following page: http://msdn.microsoft.com/en-us/library/ms228056.aspx
Here's my implementation:
First opened the DLL project (called ExcelExporter) in Visual Studio and added a new class named SectionHandler (the source was copied from the link above).
In the second step I edited the Web.config file and added in the configSections the following:
- Code: Select all
<sectionGroup name="excelexporter">
<section name="settings" type="ExcelExporter.SectionHandler" requirePermission="false"/>
</sectionGroup>
The code above defines the structure of the settings information and links it to the Class used to read it.
The second block contains the parameters ... I added this second block under configSection:
- Code: Select all
<excelexporter>
<settings>
<conn string="Initial Catalog=Northwind;Data Source=213.112.253.112\SQL2008;Connection Timeout=15"/>
<zip_filename string="report"/>
<output_directory string="C:\Inetpub\wwwroot\excelexporter\xls_out"/>
<output_dir_url string="/excelexporter/xls_out/" />
</settings>
</excelexporter>
To access settings in my DLL i use the following code:
- Code: Select all
// get a reference to the settings object
Hashtable config = (Hashtable)System.Configuration.ConfigurationSettings.GetConfig("sqlproxy/settings");
// read a value from the object
String output_directory = ((Hashtable)(config["output_directory"]))["string"].ToString();
There are probably more elegant ways to store settings, however this one is totally generic and more importantly it's working!
