Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change web.config settings in code behind

i m using a third party upload control and there r few settings in web.config

<uploadSettings allowedFileExtensions=".pdf,.xls,.doc,.zip,.rar,.jpg" scriptPath="upload_scripts" imagePath="" cssPath="upload_styles" enableManualProcessing="true" showProgressBar="true" showCancelButton="true"/>

now i want to change these settings from code behind e.g i want to make showcancelbutton="false"

how do i do that

like image 867
Mishigen Avatar asked Feb 06 '26 05:02

Mishigen


1 Answers

Since it's a web application you want to change I'd go with the WebConfigurationManager.

If the configuration value you are about to change is in a separate section you need to get that section first:

var myConfiguration = (Configuration)WebConfigurationManager.OpenWebConfiguration("~");
var section = (MySectionTypeHere)myConfiguration.GetSection("system.web/mySectionName");
//Change your settings here
myConfiguration.Save();

Keep in mind that the web application will be restarted each time you change the web.config.

An article explaining it more in detail is available here.

like image 182
PHeiberg Avatar answered Feb 09 '26 03:02

PHeiberg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!