Tuesday, 11 June 2013

Modify Web.Config AppSetting Value

Main()

{
Configuration config = OpenConfigFile(Server.MapPath("~/web.config"));
            config.AppSettings.Settings["XmlFile"].Value = "UrlRoute"+(Convert.ToInt32(fileno)+1).ToString()+".xml";
            config.Save(ConfigurationSaveMode.Modified);
            ConfigurationManager.RefreshSection("appSettings");
}


public static Configuration OpenConfigFile(string configPath)
    {
        var configFile = new FileInfo(configPath);
        var vdm = new VirtualDirectoryMapping(configFile.DirectoryName, true, configFile.Name);
        var wcfm = new WebConfigurationFileMap();
        wcfm.VirtualDirectories.Add("/", vdm);
        return WebConfigurationManager.OpenMappedWebConfiguration(wcfm, "/");
    }

No comments:

Post a Comment

C# LINQ Joins With SQL

There are  Different Types of SQL Joins  which are used to query data from more than one database tables. In this article, you will learn a...