I have created one class that directly map to ConfigSection
of web. config. My class definition is given below :
public class myConfiguration: ConfigurationSection
{
public myConfiguration()
{
//
// TODO: Add constructor logic here
//
}
[ConfigurationProperty("fileName", IsRequired = true)]
public string FileName
{
get { return this["fileName"] as string; }
}
[ConfigurationProperty("rootNode", IsRequired = true)]
public string RootNode
{
get { return this["rootNode"] as string; }
}
[ConfigurationProperty("childNode", IsRequired = true)]
public string ChildNode
{
get { return this["childNode"] as string; }
}
[ConfigurationProperty("comparableAttributes", IsRequired = true)]
public string ComparableAttributes
{
get
{ return this["comparableAttributes"] as string; }
}
}
I have created section in web.config file as below :
<configSections>
<section name="myConfigDemo" type="myConfiguration"/>
</configSections>
Then i have used this section as
<myConfigDemo fileName="myXml.xml" rootNode="world" childNode="country" comparableAttributes="id, population">
</myConfigDemo>
Now the problem is How can I assign fileName = "anotherFile.xml"
at runtime ? I have tried
[ConfigurationProperty("fileName", IsRequired = true)]
public string FileName
{
get { return this["fileName"] as string; }
set {
string str = this["fileName"] as string;
str = value; }
}
But my Visual Studio make my pc hang wen i use code above ! i Know the property is readonly when u use only get
but set
makes my pc hang !!! What can i do to change filename runtime ?