2009-11-18 95 views
3

IM和有R IN的web.config一些设置 变化web.config设置背后

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

现在我想从代码更改这些设置,如后面我想打showcancelbutton =“假”

怎么做呢

回答

0

您可以使用它驻留在system.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);

5

因为它是你想改变我与WebConfigurationManager去一个Web应用程序。

如果配置价值,你将要改变的是在一个单独的部分,你需要首先得到该节:

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

请记住,Web应用程序会在每次更改网页的时间重新启动。配置。

详细解释它的文章可以用here