I have a series of user controls which internally contain datasets. At
run-time, these datasets are loaded from XML documents in the following
manner:
private string _xmlPath = ConfigurationSettings.AppSettings["XML.Path"];
public UserControl1()
{
InitializeComponent();
this._xmlPath = ConfigurationSettings.AppSettings["XML.Path"];
string s = Path.Combine(this._xmlPath, "Doc1.xml");
this.UserControlData.ReadXml(fileName);
}
The problem is that "this._xmlPath" is never properly initialized at
design-time. I always encounter "Value cannot be null. Parameter:
path1" errors on the Path.Combine function call.
I don't actually need this data at design-time, so I could just not let
this code run in the designers. But I can't figure out how to tell when
a control is being designed or is being run. Ideally it should just
work as is, but I cannot get the configuration settings to properly load
at design-time. (I have an app.config in my project and it has been
subsequently built into an EXENAME.config file in the Debug folder...)
Any ideas?
--Mike
> I don't actually need this data at design-time, so I could just not let
> this code run in the designers. But I can't figure out how to tell when
> a control is being designed or is being run.
perhaps the retrieval of data for the UserControl should be on the OnLoad
event of the UserControl. At that event, you can test if the control is
being loaded at runtime or designtime using its DesignMode property and
execute your data retrieval statements if it is not at DesignMode (meaning
runtime).
>Ideally it should just
> work as is, but I cannot get the configuration settings to properly load
> at design-time. (I have an app.config in my project and it has been
> subsequently built into an EXENAME.config file in the Debug folder...)
app.config file becomes application.exe.config when build, i believe it's by
default. I have no idea about loading from configuration file which is part
of the project at designtime.