im 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 eg i want to make showcancelbutton="false"
how do i do that
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 .
您可以使用驻留在system.configuration中的Configuration类。
string configLocation = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
string configPath = Path.Combine(configLocation, "yourAppName");
Configuration configFile = ConfigurationManager.OpenExeConfiguration(configPath); configFile.AppSettings.Settings["TheSettingYouWantToChange"].Value = "NewValue"; configFile.Save(ConfigurationSaveMode.Modified);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.