Modify and get the Value property function in the add in the Config section of the appsettings.

Source: Internet
Author: User

   1:  //<summary>
   2:  ///Modify the Value property in the Add in the Config section of the Web. config or app. config file appsettings
   3:  //</summary>
   4:  //<remarks>
   5:  ////Note that this function will cause the entire Web application to be restarted, causing all current sessions to be lost
   6:  //</remarks>
   7:  ///<param name= "key" > key to be modified key</param>
   8:  ///<param name= "strvalue" > Modified value</param>
   9:  ///<exception cref= "" > Cannot find the relevant key </exception>
  :/  //<exception cref= "" > Insufficient permissions to save to the Web. config file </exception>
One   :  publicstaticvoid modifyappsettings (string string strvalue)
  :  {
  :      string"/configuration/appsettings/add[@key = '? ']";
  :      new XmlDocument ();
  :  
  :      "/application1.exe.config");
  :      XmlNode addkey = Domconfig.selectsinglenode ((Xpath.replace ("?", key));
  :      ifnull)
  :      {
  :          thrownew ArgumentException ("no <add key= found " "' value=.../> configuration section");
  :      }
  :      addkey.attributes["value"]. InnerText = strvalue;
  :      "/application1.exe.config");
  :  
  :  }
  £ º  
+   /  /<summary>
/   /  //////For the Value property in the Add in the Config section of the web. AppSettings or app. config file
  :/  /</summary>
  :/  //<param name= "key" > key to be modified key</param>
+   /  -<param name= "strvalue" > Modified value</param>
  :/  //<exception cref= "" > Cannot find the relevant key </exception>
+   /  /<exception cref= "" > Insufficient permissions to save to the Web. config file </exception>
  :  publicstaticstring getappsettings (string Key
  :  {
A   :      string"/configuration/appsettings/add[@key = '? ']";
  Panax notoginseng  :    new XmlDocument ();
  :  
  :      "/application1.exe.config");
Max   :      XmlNode addkey = Domconfig.selectsinglenode ((Xpath.replace ("?", key));
  :      ifnull)
  :      {
  :          thrownew ArgumentException ("no <add key= found " "' value=.../> configuration section");
  :      }
  :      return addkey.attributes["value"]. InnerText;
  :  }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.