2009-11-18 77 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