asp.net 写web.Config 文件

 public static void writeConfig(string item, string key, string value)
    {
        if (item == "")
        {
            item = "appSettings";
        }
        Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(System.Web.HttpContext.Current.Request.ApplicationPath);
        AppSettingsSection appSection = (AppSettingsSection)config.GetSection(item);
        if (appSection.Settings[key] == null)
        {
            appSection.Settings.Add(key, value);
            config.Save();
        }
        else
        {
            appSection.Settings.Remove(key);
            appSection.Settings.Add(key, value);
            config.Save();
        }
    }
posted @ 2007-12-28 12:43  peak  阅读(456)  评论(0)    收藏  举报